/**
 * 定义命名空间 
 */
Ext.ns("divo.admin.test")
Ext.ns("divo.admin.portal")
Ext.ns("divo.admin.user")
Ext.ns("divo.admin.group")
Ext.ns("divo.admin.menu")

Ext.ns("divo.xf.producer")
Ext.ns("divo.xf.projecter")
Ext.ns("divo.xf.checker")
Ext.ns("divo.xf.product")
Ext.ns("divo.xf.newproduct")
Ext.ns("divo.xf.queryproduct")
Ext.ns("divo.xf.checkreport")
Ext.ns("divo.xf.corpuser")
Ext.ns("divo.xf.mainter")
Ext.ns("divo.xf.advisor")
Ext.ns("divo.xf.auditproduct")
Ext.ns("divo.xf.querycheckreport")
//EOP
;/**
 * 咨询单位维护
 */
divo.xf.advisor.MainPanel = Ext.extend(Ext.Panel, {
	initComponent : function() {
		if (this.isCorpUser()) {
			alert("对不起，企业会员用户不能使用此功能。")
			divo.xf.producer.MainPanel.superclass.initComponent.call(this)
			return
		}
		this.portletDefinitions = [{
			id : 'info',
			text : '企业资料',
			xtype : "form.xf.AdvisorInfoDisplayForm",
			config : {
			    menuItemId : this.menuItemId
			}
		},{
			id : 'actionlog',
			text : '操作日志',
			xtype : "panel.xf.ActionLogGridPanel",
			config : {
			    menuItemId : this.menuItemId,
			    actionCode : 7
			}
		}]
	
		this.advisorGridPanelId = this.myId("advisor")
		this.portalId = this.myId('portal')
		this.portalMgr = new Ext.ux.PortalManager(
			this.portalId,
			'xf-advisor-portal',
			this.portletDefinitions)
		
		Ext.apply(this, {
			layout : 'tdgi_border',
			defaults : {
				border : false
			},
			border : false,
			items : [{
				stateful : true,
				stateId : this.myId('advisor'),
				region : 'west',
				title : '咨询单位一览',
				collapsible : false,
				ctCls : "j-toolbar-dark",
				width : 500,
				collapsedTitle : true,
				split : true,
				layout : 'fit',
				items : [{
					id : this.advisorGridPanelId,
					xtype : "panel.xf.AdvisorGridPanel",
					menuItemId : this.menuItemId
				}]
			}, {  
				region : 'center',
				layout : 'fit',
                tbar : this.portalMgr.getTbar(),
                autoScroll:true,
				ctCls : "j-toolbar-dark",
				items : [{
					xtype : 'statefulportal',
					id : this.portalId,
					items : [{
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}]
				}]
			}]	
		})

		this.subscribe("divo.rowSelect"+this.advisorGridPanelId,this.onAdvisorChange,this)

		divo.xf.advisor.MainPanel.superclass.initComponent.call(this)
	},
	onAdvisorChange : function(subj, msg, data) {
		this.portalMgr.onRefresh(msg)
	},
	initPortal : function() {
		if (!this.portalMgr) return
		this.portalMgr.init()

		Ext.ComponentMgr.get(this.portalId).on("drop", function() {
			this.portalMgr.saveState()
		},this)
	}
	
})

divo.xf.advisor.Main = function() {
	/* ----------------------- private变量 ----------------------- */
	var mp

	/* ----------------------- private方法 ----------------------- */
	// 创建布局
	function createLayout(parentPanel,menuItemId,extraInfo) {
		mp = new divo.xf.advisor.MainPanel({
			id : 'xf-advisor',
			menuItemId : menuItemId
		})
		parentPanel.add(mp)
		parentPanel.doLayout()
	}

	/* ----------------------- public方法 ----------------------- */
	return {

		// 初始化
		init : function(parentPanel, menuItemId,extraInfo) {
			createLayout(parentPanel,menuItemId,extraInfo)
			mp.initPortal()
		}

	} // return

}()
// EOP

;/**
 * 定义命名空间 
 */
Ext.ns("divo.panel")

Ext.ns("form.test")
Ext.ns("panel.test")
Ext.ns("window.test")
Ext.ns("grid.test")
Ext.ns("tree.test")
Ext.ns("data.test")

Ext.ns("panel.admin")
Ext.ns("form.admin")
Ext.ns("window.admin")
Ext.ns("tree.admin")
Ext.ns("grid.admin")

Ext.ns("panel.xf")
Ext.ns("form.xf")
Ext.ns("window.xf")
Ext.ns("grid.xf")

//EOP
;/**
 * 咨询单位网格面板
 */
panel.xf.AdvisorGridPanel = Ext.extend(divo.panel.SmartGridDetailPanel, {
	initComponent : function() {
 		this.action = new Ext.ux.grid.RowActions({
            header:'操作',
            autoWidth:false, 
            width:60,
            actions:[{
                iconCls:'icon-update',
                tooltip:'修改咨询单位',
                hide : !this.canUpdate()
            },{
                iconCls:'icon-delete',
                tooltip:'删除咨询单位',
                hide : !this.canDelete()
            }]
        })
		this.action.on('action',this.onAction,this)
	
		Ext.apply(this, {
			url : "/xf/advisors",
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				gridIdOfView : 'xf-advisor-grid', 
				filter : true,
				toolbar : this.isLookup?false:this.createToolbarBtn(),
				plugins : [this.action],
				autoExpandColumn : 'name'
			},
			autoScroll : true
		})
		
		this.subscribe("window.xf.AdvisorChanged", this.onAdvisorChanged, this)
		this.on('beforedestroy', function() {
			this.unsubscribe()
		}, this)
		
		panel.xf.AdvisorGridPanel.superclass.initComponent.apply(this,arguments)
	},
	onAction : function(grid, record, action, row, col) {
		if (action=='icon-update')
		    this.editItem()
		if (action=='icon-delete')
		    this.deleteItem()
	},
	//重写
	createGridMeta : function() {
		return this.getGridMeta(this.fieldDefinitions,this.isLookup?null:[this.action])
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		},{
			name : 'project_grade'
		},{
			name : 'name',
			header : '企业名称',
			searchable : true,
			type : 'string',
			id : 'name'
		},{
			name : 'py',
			header : '拼音助记符',
			searchable : true,
			type : 'string'
		},{
			name : 'area_name',
			header : '地区',
			type : 'string'
		}]
	},
	createToolbarBtn : function(){
		var tb = [];

		var addBtn = new Ext.Toolbar.Button( {
			text : '新建',
			tooltip : '新建咨询单位',
			icon : divo.iconAdd,
			cls : 'x-btn-text-icon',
			hidden : !this.canCreate(),
			handler : this.addItem.createDelegate(this)
		})
		tb.push(addBtn)
		return tb
	},
	addItem : function() {
		this.advisorWindowId = this.myId('win')

		var win = new window.xf.AdvisorAddOrEditWindow({
			id : this.advisorWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : true
		})
		win.show()
	},
	editItem : function() {
		if (!this.cId) {
			this.say("请先选择要修改的记录")
			return
		}
		this.advisorWindowId = this.myId('win')

		var win = new window.xf.AdvisorAddOrEditWindow({
			id : this.advisorWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : false,
			advisorId : this.cId
		})
		win.show()
	},
	onAdvisorChanged : function(subj, msg, data) {
		if (msg.sender == this.advisorWindowId) {
			this.cIdFocus = msg.id
			this.loadList()
		}
	},
	onLoadItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.fillForm(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
	},
	onDeleteItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'DELETE',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (resp.success)
					this.deleteItemCallback()
				else
				    this.sayError(resp.errors.reason) 
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	}

})

Ext.reg('panel.xf.AdvisorGridPanel', panel.xf.AdvisorGridPanel);
// EOP

;/**
 * 操作日志显示网格面板
 */
panel.xf.ActionLogGridPanel = Ext.extend(divo.panel.SmartGridPanel, {
	actionCode : null,
	initComponent : function() {
		Ext.apply(this, {
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				gridIdOfView : 'xf-action-log-grid',
				displayLoadMask : false,
				footer : false,
				filter : false,
				allowGridState : false
			},
			autoScroll : true
		})
		
		panel.xf.ActionLogGridPanel.superclass.initComponent.apply(this,arguments)
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		},{
			header: "序号", 
			width: 40, 
			sortable : false,
			renderer: this.rowNumberRender.createDelegate(this)			
		},{
			name : 'descrip',
			header : '操作',
			type : 'string',
			sortable : false,
			width: 150, 
			renderer: this.wordWrapRender.createDelegate(this)
		},{
			name : 'user_name',
			header : '操作者',
			width: 100, 
			sortable : false,
			type : 'string'
		},{
			name : 'added_on',
			header : '操作时间',
			sortable : false,
			width: 150, 
			type : 'string'
		}]
	},
	//public
	showList : function(id) {
	   if (id)
	   	   this.objId = id
	   
	   if (!this.objId) return
	   
	   this.url = "/xf/actionlogs/"+this.actionCode+"/"+this.objId
	   this.setUrl(this.url)
  	   this.loadList()
	}
})

Ext.reg('panel.xf.ActionLogGridPanel', panel.xf.ActionLogGridPanel);
// EOP

;/**
 *咨询单位新建或修改表单
 */
form.xf.AdvisorAddOrEditForm = Ext.extend(divo.form.AddOrEditForm, {
	initFocusFldName : 'name',
	advisorId : null,
	initComponent : function() {
		Ext.apply(this, {
			labelWidth : 280,
			defaultType : "textfield",
			labelAlign : "right",
			autoScroll : true,
			bodyStyle : "padding:10px",
			items : [{
				xtype : 'panel',
				border : false,
				bodyStyle : 'background:none;padding-bottom:10px',
				html : '带 (' + divo.required + ') 号栏位为必填项。'
			},{
				fieldLabel : divo.required+"企业名称",
				name : "name",
				width:300,
				listeners : {
					change : {
						scope : this,
						fn : function(o, value) {
							var py = Ext.getCmp(this.myId('py'))
							Ext.Ajax.request({
								scope : this,
								url : "/hz/pymemo",
								async : true,
								method : 'GET',
								params : {'name':o.getValue()}, 
								success : function(response, options) {
									var resp = Ext.decode(response.responseText)
									py.setValue(resp.hzpy)
								}
							})
						} //fn
					} //change
				} //listeners
			},{
				fieldLabel : "拼音助记符",
				name : "py",
				id : this.myId('py'),
				width : 300
			},{
				fieldLabel : divo.required+"资质证书编号",
				name : "qualification_number",
				width:300
			},{
				xtype : "radiogroup",
				width : 320,
				fieldLabel : "工程资质等级",
				items: [
                    {boxLabel: '一级', name: 'project_grade',inputValue: '一级', checked: true},
                    {boxLabel: '二级', name: 'project_grade',inputValue: '二级'},
                    {boxLabel: '三级', name: 'project_grade',inputValue: '三级'},
                    {boxLabel: '临时', name: 'project_grade',inputValue: '临时'}
                ]
			},{
				xtype : "radiogroup",
				width : 320,
				fieldLabel : "消防专业承包资质等级",
				items: [
                    {boxLabel: '一级', name: 'specialty_grade',inputValue: '一级', checked: true},
                    {boxLabel: '二级', name: 'specialty_grade',inputValue: '二级'},
                    {boxLabel: '三级', name: 'specialty_grade',inputValue: '三级'},
                    {boxLabel: '临时', name: 'specialty_grade',inputValue: '临时'}
                ]
			},{
				xtype : "radiogroup",
				width : 240,
				fieldLabel : "消防设计资质等级",
				items: [
                    {boxLabel: '一级', name: 'design_grade',inputValue: '一级', checked: true},
                    {boxLabel: '二级', name: 'design_grade',inputValue: '二级'},
                    {boxLabel: '没有', name: 'design_grade',inputValue: '没有'}
                ]
			},{
				xtype : 'combo',
				fieldLabel : divo.required + '所在地区',
				name : 'area_name',
				emptyText : '',
				mode : 'remote',
				editable : false,
				triggerAction : 'all',
				forceSelection : true,
				valueField : 'name',
				displayField : 'name',
				store : new Ext.data.Store({
					id : 'id',
					proxy : new Ext.data.HttpProxy({
						url : "/xf/areas",
						method : 'GET'
					}),
					reader : new Ext.data.JsonReader({
						root : 'rows',
						fields : ['id', 'name']
					})
				})
			},{
				fieldLabel : divo.required+"法定代表人",
				name : "corporation",
				maxLength : 20,
				width:300
			},{
				fieldLabel : divo.required+"法定代表人电话",
				name : "corporation_tele",
				maxLength :40,
				width:300
			},{
				fieldLabel : divo.required+"主要负责人",
				name : "leader",
				maxLength : 20,
				width:300
			},{
				fieldLabel : divo.required+"主要负责人电话",
				name : "leader_tele",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"主要负责人手机号",
				name : "leader_mobile",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"单位电话号码",
				name : "tele",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"单位传真号码",
				name : "fax",
				maxLength : 40,
				width:300
			},{
				fieldLabel : divo.required+"邮编",
				name : "post_code",
				maxLength : 10,
				width:300
			},{
				fieldLabel : divo.required+"工商注册地址",
				name : "register_address",
				width:300
			},{
				fieldLabel : divo.required+"实际经营地址",
				name : "address",
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"注册资金(万元)",
				name : "register_money",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"员工人数",
				name : "employee_count",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"技术员工人数",
				name : "tech_count",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海消防协会消防产业委员会会员单位",
				items: [
                    {boxLabel: '是', name: 'is_member',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_member',inputValue: false}
                ]
			},{
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海市消防产业诚信承诺单位",
				items: [
                    {boxLabel: '是', name: 'is_trustful',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_trustful',inputValue: false}
                ]
			},{
				fieldLabel : "备注",
				name : "note",
				width:300
			}]
		})

		form.xf.AdvisorAddOrEditForm.superclass.initComponent.call(this);
	},
	//重写
    loadItem : function() {
		Ext.Ajax.request({
			scope : this,
			url : "/xf/advisors/"+this.advisorId,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.getForm().setValues(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
    },
	// public
	save : function(callbackOnSuccess) {
		var item = this.getForm().getObjectValues()
		item.is_member = eval(item.is_member)
		item.is_trustful = eval(item.is_trustful)
		item.is_recommended = eval(item.is_recommended)

		Ext.Ajax.request({
			scope : this,
			url : "/xf/advisors"+(this.adding?"":"/"+this.advisorId),
			waitMsg : "正在提交...",
			method : (this.adding?'POST':'PUT'),
			jsonData : item,
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (!resp.success) {
					this.getForm().markInvalid(resp.errors)
				} else {
					callbackOnSuccess(resp.id)
				}
			},
			failure : function(response, options) {
				this.alert(response.responseText)	
			}
		})
	}
})

Ext.reg("form.xf.AdvisorAddOrEditForm", form.xf.AdvisorAddOrEditForm)
// EOP

;/**
 * 咨询单位企业资料显示用表单
 */
form.xf.AdvisorInfoDisplayForm = Ext.extend(divo.home.CorpInfoForm, {
	showList : function(id,msg) {
		if (!id) return
		
		Ext.Ajax.request({
			scope : this,
			url : "/xf/advisors/"+id,
			async : false,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				this.setItem(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	},
	getFormDefinitions : function() {
		return this.getFormDefinitionsOfAdvisor()
	}
})
Ext.reg("form.xf.AdvisorInfoDisplayForm", form.xf.AdvisorInfoDisplayForm)

// EOP
;/**
 * 咨询单位新建或修改窗口
 *
 * --------------------------------------------------------------
 * 消息：
 * 咨询单位新增或修改了
 * 
 * 消息名：     			
 * window.xf.AdvisorChanged    
 * 
 * 消息内容：
 * {int} sender 本组件的id值
 * --------------------------------------------------------------
 */
window.xf.AdvisorAddOrEditWindow = Ext.extend(Ext.Window, {
	cancelAction : "hide",  //还可以取值：destroy
	closeAction : "hide",
	adding : false,
	advisorId : null,
	initComponent : function() {
		Ext.apply(this,{
			title : (this.adding?'新建':'修改')+' 咨询单位',
			width : 670,
			height : 550,
			modal : true,
			stateful : true,
			stateId : 'xf-advisor-win',
			closable : true,
			maximizable : false,
			minimizable : false,
			layout : "fit",
			buttons : [{
				text : "确定",
				handler : this.onSave,
				scope : this
			}, {
				text : "取消",
				handler : this.onCancel,
				scope : this
			}],
			items : {
				xtype : "form.xf.AdvisorAddOrEditForm",
				adding : this.adding,
				advisorId : this.advisorId
			}
		});
		
		window.xf.AdvisorAddOrEditWindow.superclass.initComponent.call(this);
	},
	onSave : function() {
		this.items.itemAt(0).save(this.onSaveSucccess.createDelegate(this))
	},
	onSaveSucccess : function(id) {
		this.say(this.adding ? '新建成功, 请继续新建。':'修改已经保存')
		if (!this.adding)
		   this.close()
		else   
		   this.items.itemAt(0).clearForm()
		
		this.publish("window.xf.AdvisorChanged",{
			sender:this.id,
			id : id
		})
	}
});
// EOP

;/**
 * 消防产品核对
 */
divo.xf.auditproduct.MainPanel = Ext.extend(divo.panel.PanelWithHtmlBtns, {
	initComponent : function() {
		this.portletDefinitions = [{
			id : 'info',
			text : '产品资料',
			xtype : "form.xf.ProductDisplayForm",
			config : {
			    menuItemId : this.menuItemId
			}
		},{
			id : 'actionlog',
			text : '操作日志',
			xtype : "panel.xf.ActionLogGridPanel",
			config : {
			    menuItemId : this.menuItemId,
			    actionCode : 5
			}
		}]
	
		this.productGridPanelId = this.myId("auditproduct")
		this.portalId = this.myId('portal')
		this.portalMgr = new Ext.ux.PortalManager(
			this.portalId,
			'xf-auditproduct-portal',
			this.portletDefinitions)
		
		Ext.apply(this, {
			layout : 'tdgi_border',
			defaults : {
				border : false
			},
			border : false,
			items : [{
				stateful : true,
				stateId : this.myId('auditproduct'),
				region : 'west',
				collapsible : true,
				ctCls : "j-toolbar-dark",
				width : 600,
				collapsedTitle : true,
				split : true,
				layout : 'fit',
				items : [this.createLayoutPanel()]
			}, {  
				region : 'center',
				layout : 'fit',
                tbar : this.portalMgr.getTbar(),
                autoScroll:true,
				ctCls : "j-toolbar-dark",
				items : [{
					xtype : 'statefulportal',
					id : this.portalId,
					items : [{
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}]
				}]
			}]	
		})

		this.subscribe("divo.rowSelect"+this.productGridPanelId,this.onProducerChange,this)

		divo.xf.auditproduct.MainPanel.superclass.initComponent.call(this)
	},
	onProducerChange : function(subj, msg, data) {
		this.portalMgr.onRefresh(msg)
	},
	initPortal : function() {
		this.portalMgr.init()

		Ext.ComponentMgr.get(this.portalId).on("drop", function() {
			this.portalMgr.saveState()
		},this)
	},
	createLayoutPanel : function() {
		return new Ext.Panel({
			layout : 'border',
			defaults : {
				border : false
			},
			border : false,
			items : [this.getCenterContent(), this.createAuditProducerGrid()]
		})
	},
	createProductGrid : function() {
		return new panel.xf.AuditProductGridPanel({
			region : "center",
			autoScroll : true,
			bodyStyle : "padding:5px",
			id : this.productGridPanelId
		})
	},
	createAuditProducerGrid : function() {
		return new grid.xf.AuditProducerGrid({
			region : "west",
			stateful : true,
			stateId : this.myId('producer'),
			autoScroll : true,
			width : 250,
			split : true,
			//bodyStyle : "padding:5px",
			listeners : {
				'onSelectItem' : {
					fn : function(record) {
						Ext.getCmp(this.productGridPanelId).showList(record.data.id)
					},
					scope : this
				}
			}
		})
	},
	getCenterContent : function() {
		return new Ext.Panel({
			region : 'center',
			layout : 'border',
			defaults : {
				border : false
			},
			border : false,
			title : '待核对产品一览',
			items : [{
				region : 'center',
				layout : 'border',
				defaults : {
					border : false
				},
				border : false,
				//autoScroll : true,
				items : [this.getHtmlBtnsPanel({
					'pass' : {
						image : 'check_pass.png',
						fn :this.passProduct
					},
					'notPass' : {
						image : 'check_not-pass.png',
						fn :this.notPassProduct
					}
				}),this.createProductGrid()]
			}]	
		})
	},
	passProduct : function() {
		Ext.getCmp(this.productGridPanelId).passItem()
	},
	notPassProduct : function() {
		Ext.getCmp(this.productGridPanelId).notPassItem()
	}
})

divo.xf.auditproduct.Main = function() {
	/* ----------------------- private变量 ----------------------- */
	var mp

	/* ----------------------- private方法 ----------------------- */
	// 创建布局
	function createLayout(parentPanel,menuItemId,extraInfo) {
		mp = new divo.xf.auditproduct.MainPanel({
			id : 'xf-auditproduct',
			menuItemId : menuItemId
		})
		parentPanel.add(mp)
		parentPanel.doLayout()
	}

	/* ----------------------- public方法 ----------------------- */
	return {

		// 初始化
		init : function(parentPanel, menuItemId,extraInfo) {
			createLayout(parentPanel,menuItemId,extraInfo)
			mp.initPortal()
		}

	} // return

}()
// EOP

;/**
 * 消防产品核对网格面板
 */
panel.xf.AuditProductGridPanel = Ext.extend(divo.panel.SmartGridPanel, {
	initComponent : function() {
		Ext.apply(this, {
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				gridIdOfView : 'xf-auditproduct-grid',
				filter : true,
				//toolbar : this.isLookup ? false : this.createToolbarBtn(),
				footerSimple : true,
				autoExpandColumn : 'name'
			},
			autoScroll : true
		})

		panel.xf.AuditProductGridPanel.superclass.initComponent.apply(this,
				arguments)
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		}, {
			name : 'name',
			header : '名称',
			searchable : true,
			type : 'string',
			id : 'name'
		}, {
			name : 'spec',
			header : '型号',
			type : 'string'
		}]
	},
	// public
	showList : function(producerId) {
		this.setUrl("/xf/products/audit/producers/" + producerId)
		this.loadList()
	},
	passItem : function() {
		if (!this.cId) {
			this.say("请先选择要核对通过的记录")
			return
		}
		Ext.MessageBox.confirm("确认", "产品要通过核对么？", this.passItemConfirm
				.createDelegate(this))
	},
	passItemConfirm : function(btn) {
		if (btn == "yes") {
			this.onPassItem()
		}
	},
	onPassItem : function() {
		Ext.Ajax.request({
			scope : this,
			url : '/xf/products/' + this.cId + '/audit/pass',
			method : 'PUT',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (resp.success)
					this.loadList()
				else
					this.say(resp.errors.reason)
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	},
	notPassItem : function() {
		if (!this.cId) {
			this.say("请先选择要核对不通过的记录")
			return
		}
		Ext.MessageBox.prompt("输入提示框", "请输入核对不通过的原因：", this.notPassItemConfirm.createDelegate(this))
	},
	notPassItemConfirm : function(btn, text) {
		if (btn!="ok") 
		    return
		    
		if (text=="") {
			this.say("请输入核对不通过的原因")
			return
		}
		Ext.Ajax.request({
			scope : this,
			method : 'PUT',
			url : '/xf/products/' + this.cId + '/audit/notpass',
			jsonData : {'text':text},
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (resp.success)
					this.loadList()
				else
					this.say(resp.errors.reason)
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	}

})

Ext.reg('panel.xf.AuditProductGridPanel', panel.xf.AuditProductGridPanel);
// EOP

;/**
 * 消防产品完整信息显示用表单
 */
form.xf.ProductDisplayForm = Ext.extend(divo.form.DivoBasicForm, {
	initComponent : function() {
		Ext.apply(this, {
			formType : "readOnly",
			tableClass : "j-grid-table",
			readOnly : true,
			alternateRows : false,
			labelClass : "label",
			labelWidth : "30%",
			fieldDefinitions : this.getFormDefinitions()
		})
		form.xf.ProductDisplayForm.superclass.initComponent.call(this)
	},
	getFormDefinitions : function() {
		return [{
			field : "name",
			label : "产品名称",
			dataType : "string"
		}, {
			field : "producer_name",
			label : "产品生产单位",
			dataType : "string"
		}, {
			field : "spec",
			label : "产品型号",
			dataType : "string"
		}, {
			field : "unit_name",
			label : "计量单位",
			dataType : "string"
		}, {
			field : "cat_code_1",
			label : "产品分类",
			mapping : function(item) {
				return item.cat_name_1+"->"+item.cat_name_2
			},
			dataType : "string"
		}, {
			field : "brand",
			label : "商标",
			dataType : "string"
		}, {
			field : "auth_type",
			label : "认证类别",
			dataType : "string"
		}, {
			field : "auth_code",
			label : "认证编号",
			dataType : "string"
		}, {
			field : "end_date",
			label : "认证有效期",
			dataType : "string"
		}, {
			field : "report_date",
			label : "报告签发日期",
			dataType : "string"
		}, {
			field : "report_code",
			label : "验证报告编号",
			dataType : "string"
		}, {
			field : "change_report_date",
			label : "发换证报告日期",
			dataType : "string"
		}]
	},
	//public
	showList : function(id,msg) {
		if (!id) return
		Ext.Ajax.request({
			scope : this,
			url : "/xf/products/"+id,
			async : false,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				this.setItem(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	}
	
})

Ext.reg("form.xf.ProductDisplayForm", form.xf.ProductDisplayForm)
// EOP
;/**
 * 有产品等待审核的生产厂家网格
 */
grid.xf.AuditProducerGrid = Ext.extend(divo.grid.SimpleGrid, {
	initComponent : function() {
		Ext.apply(this, {
			fieldDefinitions : this.getListDefinitions(),
			dataStore : this.buildStore(),
			loadingMessage : false
		})
		grid.xf.AuditProducerGrid.superclass.initComponent.call(this)
	},
	render : function() {
		grid.xf.AuditProducerGrid.superclass.render.apply(this, arguments)
		this.loadData()
	},
	//重写
	onSelectRow : function(view, rowAt, item, e) {
		if (e.target.innerHTML) return //点击第2列等无效
		grid.xf.AuditProducerGrid.superclass.onSelectRow.apply(this, arguments)
	},
	buildStore : function() {
		var cols = [{
			name : "id",
			type : "int"
		}, {
			name : "name",
			type : "string"
		}]
		return new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				method : 'GET',
				url : "/xf/products/producers/auditwaiting"
			}),
			reader : new Ext.data.JsonReader({
				root : 'rows',
				totalProperty : 'totalCount',
				id : 'id'
			}, Ext.data.Record.create(cols))
		})
	},
	onSelectItem : function(view, id, record) {
		this.fireEvent("onSelectItem", record)
	},
	getListDefinitions : function() {
		return [{
			field : "id",
			label : "",
			width : "0%",
			renderer : this.renderRadio.createDelegate(this)
		}, {
			field : "name",
			label : "产品生产单位",
			dataType : "string"
			//width : "100%"
		}]
	},
	renderRadio : function(v, p, record) {
		var html = "<input type=\"radio\" name=\"{0}\" id=\"{1}\"/>"
		return String.format(html,	this.myId("radio"), this.myId("radio")+record.data.id)
	}
})
Ext.reg("grid.xf.AuditProducerGrid",grid.xf.AuditProducerGrid)
// EOP
;/**
 * 消防系统检测单位维护
 */
divo.xf.checker.MainPanel = Ext.extend(Ext.Panel, {
	initComponent : function() {
		if (this.isCorpUser()) {
			alert("对不起，企业会员用户不能使用此功能。")
			divo.xf.checker.MainPanel.superclass.initComponent.call(this)
			return
		}
		this.portletDefinitions = [{
			id : 'info',
			text : '企业资料',
			xtype : "form.xf.CheckerInfoDisplayForm",
			config : {
			    menuItemId : this.menuItemId
			}
		},{
			id : 'actionlog',
			text : '操作日志',
			xtype : "panel.xf.ActionLogGridPanel",
			config : {
			    menuItemId : this.menuItemId,
			    actionCode : 3
			}
		}]
	
		this.checkerGridPanelId = this.myId("checker")
		this.portalId = this.myId('portal')
		this.portalMgr = new Ext.ux.PortalManager(
			this.portalId,
			'xf-checker-portal',
			this.portletDefinitions)
		
		Ext.apply(this, {
			layout : 'tdgi_border',
			defaults : {
				border : false
			},
			border : false,
			items : [{
				stateful : true,
				stateId : this.myId('checker'),
				region : 'west',
				title : '消防系统检测单位一览',
				collapsible : false,
				ctCls : "j-toolbar-dark",
				width : 500,
				collapsedTitle : true,
				split : true,
				layout : 'fit',
				items : [{
					id : this.checkerGridPanelId,
					xtype : "panel.xf.CheckerGridPanel",
					menuItemId : this.menuItemId
				}]
			}, {  
				region : 'center',
				layout : 'fit',
                tbar : this.portalMgr.getTbar(),
                autoScroll:true,
				ctCls : "j-toolbar-dark",
				items : [{
					xtype : 'statefulportal',
					id : this.portalId,
					items : [{
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}]
				}]
			}]	
		})

		this.subscribe("divo.rowSelect"+this.checkerGridPanelId,this.onCheckerChange,this)

		divo.xf.checker.MainPanel.superclass.initComponent.call(this)
	},
	onCheckerChange : function(subj, msg, data) {
		this.portalMgr.onRefresh(msg)
	},
	initPortal : function() {
		if (!this.portalMgr) return
		this.portalMgr.init()

		Ext.ComponentMgr.get(this.portalId).on("drop", function() {
			this.portalMgr.saveState()
		},this)
	}
	
})

divo.xf.checker.Main = function() {
	/* ----------------------- private变量 ----------------------- */
	var mp

	/* ----------------------- private方法 ----------------------- */
	// 创建布局
	function createLayout(parentPanel,menuItemId,extraInfo) {
		mp = new divo.xf.checker.MainPanel({
			id : 'xf-checker',
			menuItemId : menuItemId
		})
		parentPanel.add(mp)
		parentPanel.doLayout()
	}

	/* ----------------------- public方法 ----------------------- */
	return {

		// 初始化
		init : function(parentPanel, menuItemId,extraInfo) {
			createLayout(parentPanel,menuItemId,extraInfo)
			mp.initPortal()
		}

	} // return

}()
// EOP

;/**
 * 消防工程消防系统检测单位网格面板
 */
panel.xf.CheckerGridPanel = Ext.extend(divo.panel.SmartGridDetailPanel, {
	initComponent : function() {
 		this.action = new Ext.ux.grid.RowActions({
            header:'操作',
            autoWidth:false, 
            width:60,
            actions:[{
                iconCls:'icon-update',
                tooltip:'修改检测',
                hide : !this.canUpdate()
            },{
                iconCls:'icon-delete',
                tooltip:'删除检测',
                hide : !this.canDelete()
            }]
        })
		this.action.on('action',this.onAction,this)
	
		Ext.apply(this, {
			url : "/xf/checkers",
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				gridIdOfView : 'xf-checker-grid', 
				filter : true,
				toolbar : this.isLookup?false:this.createToolbarBtn(),
				plugins : [this.action],
				autoExpandColumn : 'name'
			},
			autoScroll : true
		})
		
		this.subscribe("window.xf.CheckerChanged", this.onCheckerChanged, this)
		this.on('beforedestroy', function() {
			this.unsubscribe()
		}, this)
		
		panel.xf.CheckerGridPanel.superclass.initComponent.apply(this,arguments)
	},
	onAction : function(grid, record, action, row, col) {
		if (action=='icon-update')
		    this.editItem()
		if (action=='icon-delete')
		    this.deleteItem()
	},
	//重写
	createGridMeta : function() {
		return this.getGridMeta(this.fieldDefinitions,this.isLookup?null:[this.action])
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		},{
			name : 'name',
			header : '企业名称',
			searchable : true,
			type : 'string',
			id : 'name'
		},{
			name : 'py',
			header : '拼音助记符',
			searchable : true,
			type : 'string'
		},{
			name : 'area_name',
			header : '地区',
			type : 'string'
		}]
	},
	createToolbarBtn : function(){
		var tb = [];

		var addBtn = new Ext.Toolbar.Button( {
			text : '新建',
			tooltip : '新建消防系统检测单位',
			icon : divo.iconAdd,
			cls : 'x-btn-text-icon',
			hidden : !this.canCreate(),
			handler : this.addItem.createDelegate(this)
		})
		tb.push(addBtn)
		return tb
	},
	addItem : function() {
		this.checkerWindowId = this.myId('win')

		var win = new window.xf.CheckerAddOrEditWindow({
			id : this.checkerWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : true
		})
		win.show()
	},
	editItem : function() {
		if (!this.cId) {
			this.say("请先选择要修改的记录")
			return
		}
		this.checkerWindowId = this.myId('win')

		var win = new window.xf.CheckerAddOrEditWindow({
			id : this.checkerWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : false,
			checkerId : this.cId
		})
		win.show()
	},
	onCheckerChanged : function(subj, msg, data) {
		if (msg.sender == this.checkerWindowId) {
			this.cIdFocus = msg.id
			this.loadList()
		}
	},
	onLoadItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.fillForm(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
	},
	onDeleteItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'DELETE',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (resp.success)
					this.deleteItemCallback()
				else
				    this.sayError(resp.errors.reason) 
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	}

})

Ext.reg('panel.xf.CheckerGridPanel', panel.xf.CheckerGridPanel);
// EOP

;/**
 * 消防系统检测单位新建或修改表单
 */
form.xf.CheckerAddOrEditForm = Ext.extend(divo.form.AddOrEditForm, {
	initFocusFldName : 'name',
	checkerId : null,
	initComponent : function() {
		Ext.apply(this, {
			labelWidth : 280,
			defaultType : "textfield",
			labelAlign : "right",
			autoScroll : true,
			bodyStyle : "padding:10px",
			items : [{
				xtype : 'panel',
				border : false,
				bodyStyle : 'background:none;padding-bottom:10px',
				html : '带 (' + divo.required + ') 号栏位为必填项。'
			}, {
				fieldLabel : divo.required + "企业名称",
				name : "name",
				width : 300,
				listeners : {
					change : {
						scope : this,
						fn : function(o, value) {
							var py = Ext.getCmp(this.myId('py'))
							Ext.Ajax.request({
								scope : this,
								url : "/hz/pymemo",
								async : true,
								method : 'GET',
								params : {'name':o.getValue()}, 
								success : function(response, options) {
									var resp = Ext.decode(response.responseText)
									py.setValue(resp.hzpy)
								}
							})
						} //fn
					} //change
				} //listeners
			}, {
				fieldLabel : "拼音助记符",
				name : "py",
				id : this.myId('py'),
				width : 300
			}, {
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "检测资质等级",
				items: [
                    {boxLabel: '一级', name: 'grade',inputValue: '一级', checked: true},
                    {boxLabel: '二级', name: 'grade',inputValue: '二级'}
                ]
			}, {
				xtype : 'combo',
				fieldLabel : divo.required + '所在地区',
				name : 'area_name',
				emptyText : '',
				mode : 'remote',
				editable : false,
				triggerAction : 'all',
				forceSelection : true,
				valueField : 'name',
				displayField : 'name',
				store : new Ext.data.Store({
					id : 'id',
					proxy : new Ext.data.HttpProxy({
						url : "/xf/areas",
						method : 'GET'
					}),
					reader : new Ext.data.JsonReader({
						root : 'rows',
						fields : ['id', 'name']
					})
				})
			}, {
				fieldLabel : divo.required + "法定代表人",
				name : "corporation",
				maxLength : 20,
				width : 300
			}, {
				fieldLabel : divo.required + "法定代表人电话",
				name : "corporation_tele",
				maxLength : 40,
				width : 300
			}, {
				fieldLabel : divo.required + "主要负责人",
				name : "leader",
				maxLength : 20,
				width : 300
			}, {
				fieldLabel : divo.required + "主要负责人电话",
				name : "leader_tele",
				maxLength : 40,
				width : 180
			}, {
				fieldLabel : divo.required + "主要负责人手机号",
				name : "leader_mobile",
				maxLength : 40,
				width : 180
			}, {
				fieldLabel : divo.required + "单位电话号码",
				name : "tele",
				maxLength : 40,
				width : 180
			}, {
				fieldLabel : divo.required + "单位传真号码",
				name : "fax",
				maxLength : 40,
				width : 300
			}, {
				fieldLabel : divo.required + "邮编",
				name : "post_code",
				maxLength : 10,
				width : 300
			}, {
				fieldLabel : divo.required + "工商注册地址",
				name : "register_address",
				width : 300
			}, {
				fieldLabel : divo.required + "实际经营地址",
				name : "address",
				width : 300
			}, {
				xtype : 'numberfield',
				fieldLabel : divo.required + "注册资金(万元)",
				name : "register_money",
				decimalPrecision : 0,
				allowNegative : false,
				width : 300
			}, {
				xtype : 'numberfield',
				fieldLabel : divo.required + "员工人数",
				name : "employee_count",
				decimalPrecision : 0,
				allowNegative : false,
				width : 300
			}, {
				xtype : 'numberfield',
				fieldLabel : divo.required + "技术员工人数",
				name : "tech_count",
				decimalPrecision : 0,
				allowNegative : false,
				width : 300
			}, {
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海消防协会消防产业委员会会员单位",
				items: [
                    {boxLabel: '是', name: 'is_member',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_member',inputValue: false}
                ]
			}, {
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海市消防产业诚信承诺单位",
				items: [
                    {boxLabel: '是', name: 'is_trustful',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_trustful',inputValue: false}
                ]
			}, {
				fieldLabel : divo.required + "计量认证标志编号",
				name : "auth_code",
				maxLength : 10,
				width : 300
			}, {
				fieldLabel :"单位编号",
				name : "code",
				width : 100
			}, {
				fieldLabel : "备注",
				name : "note",
				width : 300
			}]
		})

		form.xf.CheckerAddOrEditForm.superclass.initComponent.call(this);
	},
	//重写
	loadItem : function() {
		Ext.Ajax.request({
			scope : this,
			url : "/xf/checkers/" + this.checkerId,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.getForm().setValues(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
	},
	// public
	save : function(callbackOnSuccess) {
		var item = this.getForm().getObjectValues()
		item.is_member = eval(item.is_member)
		item.is_trustful = eval(item.is_trustful)
		item.is_recommended = eval(item.is_recommended)

		Ext.Ajax.request({
			scope : this,
			url : "/xf/checkers" + (this.adding ? "" : "/" + this.checkerId),
			waitMsg : "正在提交...",
			method : (this.adding ? 'POST' : 'PUT'),
			jsonData : item,
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (!resp.success) {
					this.getForm().markInvalid(resp.errors)
				} else {
					callbackOnSuccess(resp.id)
				}
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	}
})

Ext.reg("form.xf.CheckerAddOrEditForm", form.xf.CheckerAddOrEditForm)
// EOP

;/**
 * 消防系统检测单位企业资料显示用表单
 */
form.xf.CheckerInfoDisplayForm = Ext.extend(divo.home.CorpInfoForm, {
	//public
	showList : function(id,msg) {
		if (!id) return
		
		Ext.Ajax.request({
			scope : this,
			url : "/xf/checkers/"+id,
			async : false,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				this.setItem(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	},
	getFormDefinitions : function() {
		return this.getFormDefinitionsOfChecker()
	}
})
Ext.reg("form.xf.CheckerInfoDisplayForm", form.xf.CheckerInfoDisplayForm)

// EOP
;/**
 * 消防系统检测单位新建或修改窗口
 *
 * --------------------------------------------------------------
 * 消息：
 * 消防系统检测单位新增或修改了
 * 
 * 消息名：     			
 * window.xf.CheckerChanged    
 * 
 * 消息内容：
 * {int} sender 本组件的id值
 * --------------------------------------------------------------
 */
window.xf.CheckerAddOrEditWindow = Ext.extend(Ext.Window, {
	cancelAction : "hide",  //还可以取值：destroy
	closeAction : "hide",
	adding : false,
	checkerId : null,
	initComponent : function() {
		Ext.apply(this,{
			title : (this.adding?'新建':'修改')+'消防系统检测单位',
			width : 670,
			height : 550,
			modal : true,
			stateful : true,
			stateId : 'xf-checker-win',
			closable : true,
			maximizable : false,
			minimizable : false,
			layout : "fit",
			buttons : [{
				text : "确定",
				handler : this.onSave,
				scope : this
			}, {
				text : "取消",
				handler : this.onCancel,
				scope : this
			}],
			items : {
				xtype : "form.xf.CheckerAddOrEditForm",
				adding : this.adding,
				checkerId : this.checkerId
			}
		});
		
		window.xf.CheckerAddOrEditWindow.superclass.initComponent.call(this);
	},
	onSave : function() {
		this.items.itemAt(0).save(this.onSaveSucccess.createDelegate(this))
	},
	onSaveSucccess : function(id) {
		this.say(this.adding ? '新建成功, 请继续新建。':'修改已经保存')
		if (!this.adding)
		   this.close()
		else   
		   this.items.itemAt(0).clearForm()
		
		this.publish("window.xf.CheckerChanged",{
			sender:this.id,
			id : id
		})
	}
});
// EOP

;/**
 * 会员审核
 */
divo.xf.corpuser.MainPanel = Ext.extend(divo.panel.PanelWithHtmlBtns, {
	initComponent : function() {
		this.corpUserGridPanelId = this.myId('corpUser')
		this.portletDefinitions = [{
			id : 'user-groups',
			text : '所属用户组',
			xtype : "panel.xf.CorpUserGroupsGridPanel",
			config : {
			    menuItemId : this.menuItemId
			}
		},{
			id : 'corp-info',
			text : '企业资料',
			xtype : "panel.xf.CorpInfoDisplayPanel",
			config : {
			    menuItemId : this.menuItemId
			}
		}]
	
		this.corpUserGridPanelId = this.myId("corp")
		this.portalId = this.myId('portal')
		this.portalMgr = new Ext.ux.PortalManager(
			this.portalId,
			'xf-corpuser-portal',
			this.portletDefinitions)
		
		Ext.apply(this, {
			layout : 'tdgi_border',
			defaults : {
				border : false
			},
			border : false,
			items : [{
				stateful : true,
				stateId : this.myId('corp'),
				region : 'west',
				title : '等待审核企业会员一览',
				collapsible : false,
				ctCls : "j-toolbar-dark",
				width : 600,
				collapsedTitle : true,
				split : true,
				layout : 'fit',
                items : [this.getCenterContent()]
			}, {  
				region : 'center',
				layout : 'fit',
                tbar : this.portalMgr.getTbar(),
                autoScroll:true,
				ctCls : "j-toolbar-dark",
				items : [{
					xtype : 'statefulportal',
					id : this.portalId,
					items : [{
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}]
				}]
			}]	
		})

		this.subscribe("divo.rowSelect"+this.corpUserGridPanelId,this.onCorpUserChange,this)

		divo.xf.corpuser.MainPanel.superclass.initComponent.call(this)
	},
	onCorpUserChange : function(subj, msg, data) {
		this.portalMgr.onRefresh(msg)
 	},
	getCenterContent : function() {
		return new Ext.Panel({
			layout : 'border',
			defaults : {
				border : false
			},
			border : false,
			items : [{
				region : 'center',
				layout : 'fit',
				autoScroll : true,
				items : [{
					id : this.corpUserGridPanelId,
					xtype : "panel.xf.CorpUserGridPanel",
					menuItemId : this.menuItemId
				}]
			}, this.getHtmlBtnsPanel({
					'auditing' : {
						image : 'audit_pass.png',
						fn :this.auditingCorpUser
					}
				})]
		})
	},

	auditingCorpUser : function() {
		Ext.getCmp(this.corpUserGridPanelId).auditCorpUser()
	},

	initPortal : function() {
		this.portalMgr.init()

		Ext.ComponentMgr.get(this.portalId).on("drop", function() {
			this.portalMgr.saveState()
		},this)
	}
})

divo.xf.corpuser.Main = function() {
	/* ----------------------- private变量 ----------------------- */
	var mp

	/* ----------------------- private方法 ----------------------- */
	// 创建布局
	function createLayout(parentPanel,menuItemId,extraInfo) {
		mp = new divo.xf.corpuser.MainPanel({
			id : 'xf-corpuser',
			menuItemId : menuItemId
		})
		parentPanel.add(mp)
		parentPanel.doLayout()
	}

	/* ----------------------- public方法 ----------------------- */
	return {

		// 初始化
		init : function(parentPanel, menuItemId,extraInfo) {
			createLayout(parentPanel,menuItemId,extraInfo)
			mp.initPortal()
		}

	} // return

}()
// EOP

;/**
 * 企业会员审核
 */
panel.xf.CorpUserGridPanel = Ext.extend(divo.panel.SmartGridPanel, {
	initComponent : function() {
		Ext.apply(this, {
			url : "/xf/corpusers",
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				filter : true,
				gridIdOfView : 'xf-corp-user-grid',
				displayLoadMask : false,
				footerSimple : true,
				autoExpandColumn : 'corp_name'
			},
			autoScroll : true
		})

		panel.xf.CorpUserGridPanel.superclass.initComponent.apply(this,
				arguments)
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		}, {
			name : 'corp_name',
			header : '企业名称',
			type : 'string',
			searchable : true,
			id : 'corp_name'
		}, {
			name : 'name',
			header : '用户名',
			searchable : true,
			type : 'string'
		}, {
			name : 'user_id',
			type : 'int'
		}, {
			name : 'added_on',
			header : '注册时间',
			type : 'string'
		}, {
			name : 'producer_id',
			type : 'int'
		}, {
			name : 'projecter_id',
			type : 'int'
		}, {
			name : 'mainter_id',
			type : 'int'
		}, {
			name : 'checker_id',
			type : 'int'
		},{
			name : 'advisor_id',
			type : 'int'
		},{
			header : '用户类别',
			name : 'user_type',
			type : 'string',
			sortable : false,
			convert : function(v, rec) {
				if (rec.producer_id)
					return "产品生产单位"
				if (rec.projecter_id)
					return "工程施工单位"
				if (rec.checker_id)
					return "消防系统检测单位"
				if (rec.mainter_id)
					return "灭火器维修单位"
				if (rec.advisor_id)
					return "咨询单位"		
				return ""	
			}
		}]
	},
	auditCorpUser : function() {
		if (!this.checkSelection("请先选择企业会员"))
			return
		var record = this.getCurrentRecord()

		Ext.MessageBox.confirm('确认', '要通过审核吗？',
				this.auditCorpUserConfirm.createDelegate(this))
	},
	auditCorpUserConfirm : function(btn) {
		if (btn !== 'yes')
			return

		var ok = false
		var record = this.getCurrentRecord()
		var successMsg = record.data.name+"已经通过审核"
		Ext.Ajax.request({
			scope : this,
			url : "/xf/corpusers/" + record.data.id + "/auditstate",
			async : false,
			method : 'PUT',
			jsonData : {
				userName : this.getUserFullName()
			},
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (resp.success) {
					this.say(successMsg)
					ok = true
				} else {
					this.say(resp.errors.reason)
				}
			},
			failure : function(response, options) {
				this.alert(response.responseText)
				ok = false
			}
		})
		if (ok)
			this.loadList()
	}
})

Ext.reg('panel.xf.CorpUserGridPanel', panel.xf.CorpUserGridPanel);
// EOP

;/**
 * 企业资料显示面板（用于企业会员审核）
 */
panel.xf.CorpInfoDisplayPanel = Ext.extend(Ext.Panel, {
	initComponent : function() {
		Ext.apply(this, {
			layout : "card",
			activeItem : 0,
			items : [{
				id : this.myId('checker'),
				xtype : "form.xf.CheckerInfoDisplayForm"
			}, {
				id : this.myId('mainter'),
				xtype : "form.xf.MainterInfoDisplayForm"
			}, {
				id : this.myId('projecter'),
				xtype : "form.xf.ProjecterInfoDisplayForm"
			}, {
				id : this.myId('producer'),
				xtype : "form.xf.ProducerInfoDisplayForm"
			}, {
				id : this.myId('advisor'),
				xtype : "form.xf.AdvisorInfoDisplayForm"
			}]
		})
		panel.xf.CorpInfoDisplayPanel.superclass.initComponent.call(this)
	},
	// public
	showList : function(id, msg) {
		if (!id)
			return

		var data = msg.record.data
		if (data.checker_id) {
			this.getLayout().setActiveItem(0)
			Ext.getCmp(this.myId('checker')).showList(data.checker_id)
		}
		if (data.mainter_id) {
			this.getLayout().setActiveItem(1)
			Ext.getCmp(this.myId('mainter')).showList(data.mainter_id)
		}
		if (data.projecter_id) {
			this.getLayout().setActiveItem(2)
			Ext.getCmp(this.myId('projecter')).showList(data.projecter_id)
		}
		if (data.producer_id) {
			this.getLayout().setActiveItem(3)
			Ext.getCmp(this.myId('producer')).showList(data.producer_id)
		}
		if (data.advisor_id) {
			this.getLayout().setActiveItem(4)
			Ext.getCmp(this.myId('advisor')).showList(data.advisor_id)
		}
	}
})

Ext.reg("panel.xf.CorpInfoDisplayPanel", panel.xf.CorpInfoDisplayPanel)
// EOP
;/**
 * 用户所属用户组管理
 */
panel.admin.UserGroupsGridPanel = Ext.extend(divo.panel.SmartGridPanel, {
	initComponent : function() {
 		this.action = new Ext.ux.grid.RowActions({
            header:'',
            actions:[{
                iconCls:'icon-delete',
                tooltip:'删除与此用户组关联'
            }]
        })
		this.action.on('action',this.onAction,this)
	
		Ext.apply(this, {
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				gridIdOfView : 'admin-user-groups-grid',
				toolbar : this.createToolbarBtn(),
				plugins : [this.action],
				footer : false,
				displayLoadMask : false,
				autoExpandColumn : 'name'
			},
			autoScroll : true
		})
		
		this.subscribe("window.admin.UserGroupsChanged",this.onUserGroupsChanged,this)
		this.on('beforedestroy',function() {
		      this.unsubscribe()
		},this)
		
		panel.admin.UserGroupsGridPanel.superclass.initComponent.apply(this,arguments)
	},
	onAction : function(grid, record, action, row, col) {
		if (action=='icon-delete')
		    this.deleteUserGroup(record.data.id)
	},
	//重写
	createGridMeta : function() {
		return this.getGridMeta(this.fieldDefinitions,this.isLookup?null:[this.action])
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		},{
			name : 'name',
			header : '名称',
			type : 'string',
			id : 'name'
		}]
	},
	// 添加工具条按钮
	createToolbarBtn : function(){
		var tb = [];

		var addBtn = new Ext.Toolbar.Button( {
			text : '选择',
			tooltip : '指定所属用户组',
			icon : divo.iconAdd,
			cls : 'x-btn-text-icon',
			handler : this.selectUserGroups.createDelegate(this)
		})
		tb.push(addBtn)
		return tb
	},
	selectUserGroups : function() {
		if (!this.validate()) {
			return
		}
		this.userAndGroupWindowId = this.myId('win')
		
		var win = new window.admin.UserAndGroupWindow({
			id : this.userAndGroupWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			userId : this.userId,
			userName : this.getUserFullName()
		})
		win.show()
	},
	onUserGroupsChanged : function(subj, msg, data) {
		if (msg.sender==this.userAndGroupWindowId) {
			this.showList()
		}
	},
	deleteUserGroup : function(groupId) {
		if (!this.validate()) {
			return
		}
		var ok = true
		Ext.Ajax.request({
			scope : this,
			url : "/users/"+this.userId+"/groups/"+groupId,
			async : false,
			method : 'DELETE',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (!resp.success) {
					ok = false
				    this.say(resp.errors.reason)
				}     
			},
			failure : function(response, options) {
				this.alert(response.responseText)
				ok = false
			}
		});
		if (ok) {
			this.showList()
		}
	},
	validate : function() {
		if (!this.userId) {
			this.say("请选择用户")
			return false
		}
		if (this.userId == 1) {
			this.say("系统管理用户不允许变动所属用户组")
			return false
		}
		return true
	},
	//public
	showList : function(userId) {
	   if (userId)
	   	   this.userId = userId
	   
	   if (!this.userId) return
	   
	   this.setUrl("/users/"+this.userId+"/groups")
  	   this.loadList()
	},
	getUserFullName : function() {
		var fullName = ''
		Ext.Ajax.request({
			scope : this,
			url : "/users/"+this.userId,
			async : false,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (!resp.success) {
					this.say(resp.errors.reason)
					return
				}
				fullName = resp.data.full_name
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
		return fullName
	}
})

Ext.reg('panel.admin.UserGroupsGridPanel', panel.admin.UserGroupsGridPanel);
// EOP

;/**
 * 选择所属用户组表单
 */
form.admin.UserAndGroupForm = Ext.extend(Ext.form.FormPanel, {
	userId : null,
	initComponent : function() {
		
		Ext.apply(this, {
			baseCls : "x-plain",
			labelWidth : 75,
			labelAlign : "right",
			autoScroll : true,
			bodyStyle : "padding:0",
			items : [{
				xtype : "itemselector",
				name : 'user_groups',
				hideLabel : true,
				fromStore:this.getFromDataStore(),
				toStore:this.getToDataStore(),
				msWidth:250,
				msHeight:200,
				valueField : "id",
				displayField : "name",
				toLegend:"已选",
				fromLegend:"候选",
				drawUpIcon:false,
				drawDownIcon:false,
				drawTopIcon:false,
				drawBotIcon:false
			}]
		});

		form.admin.UserAndGroupForm.superclass.initComponent.call(this);
	},
	// 保存选择的用户组
	save : function(callbackOnSuccess) {	
		var itemStr = this.getForm().getObjectValues()
		if (itemStr.user_groups.length>0)
		    var items = itemStr.user_groups
		else    
		    var items = null 

		//删除现有全部所属用户组
		if (!this.deleteAll()) return
		
		//存入新的用户组
		var ok = true
		if (items) {
		    ok = this.saveAll(items)
		}
		if (ok) {
			this.say("选择的用户组已经保存")
			callbackOnSuccess.call()
		}
	},
	getFromDataStore : function() {
		return new Ext.data.Store({					 
			autoLoad: true,
			proxy : new Ext.data.HttpProxy( {
				method : 'GET',
				url : "/users/"+this.userId+"/groups/avaiable"
			}),
			reader: this.getReader(),
			sortInfo:{field:'name', direction:'ASC'},
        	listeners: {
        		loadexception: function(o,options,response,e) {
			 		divo.showError(response.responseText,'数据加载失败')
        		},
        		scope: this
        	}
		})		
	},
	getToDataStore : function() {
		return new Ext.data.Store({					 
			autoLoad: true,
			proxy : new Ext.data.HttpProxy( {
				method : 'GET',
				url : "/users/"+this.userId+"/groups"
			}),
			reader: this.getReader(),
			sortInfo:{field:'name', direction:'ASC'}
		})		
	},
	getReader : function() {
		return new Ext.data.JsonReader({
			idProperty:'id',
			root:'rows',
			fields: [
				{name: 'id', type: 'int'},
				{name: 'name', type: 'string'}
			]
		})		
	},
	deleteAll : function() {
		var ok = true
		Ext.Ajax.request({
			scope : this,
			url : "users/"+this.userId+"/groups",
			async : false,
			method : 'DELETE',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (!resp.success) {
					ok = false
				    this.say(resp.errors.reason)
				}     
			},
			failure : function(response, options) {
				this.alert(response.responseText)
				ok = false
			}
		});
		return ok
	},
	saveAll : function(items) {
		var ok = true
		Ext.Ajax.request({
			scope : this,
			url : "users/"+this.userId+"/groups",
			async : false,
			method : 'POST',
			jsonData : {idList:items}, //用逗号分隔的id值列表
			failure : function(response, options) {
				this.alert(response.responseText)
				ok = false
			}
		});
		return ok
	}
});

Ext.reg("form.admin.UserAndGroupForm", form.admin.UserAndGroupForm);
// EOP

;/**
 * 灭火器维修单位企业资料显示用表单
 */
form.xf.MainterInfoDisplayForm = Ext.extend(divo.home.CorpInfoForm, {
	showList : function(id,msg) {
		if (!id) return
		
		Ext.Ajax.request({
			scope : this,
			url : "/xf/mainters/"+id,
			async : false,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				this.setItem(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	},
	getFormDefinitions : function() {
		return this.getFormDefinitionsOfMainter()
	}
})
Ext.reg("form.xf.MainterInfoDisplayForm", form.xf.MainterInfoDisplayForm)

// EOP
;/**
 * 工程施工单位企业资料显示用表单
 */
form.xf.ProjecterInfoDisplayForm = Ext.extend(divo.home.CorpInfoForm, {
	showList : function(id,msg) {
		if (!id) return
		
		Ext.Ajax.request({
			scope : this,
			url : "/xf/projecters/"+id,
			async : false,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				this.setItem(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	},
	getFormDefinitions : function() {
		return this.getFormDefinitionsOfProjecter()
	}
})
Ext.reg("form.xf.ProjecterInfoDisplayForm", form.xf.ProjecterInfoDisplayForm)

// EOP
;/**
 * 产品生产单位企业资料显示用表单
 */
form.xf.ProducerInfoDisplayForm = Ext.extend(divo.home.CorpInfoForm, {
	showList : function(id,msg) {
		if (!id) return
		
		Ext.Ajax.request({
			scope : this,
			url : "/xf/producers/"+id,
			async : false,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				this.setItem(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	},
	getFormDefinitions : function() {
		return this.getFormDefinitionsOfProducer()
	}
})
Ext.reg("form.xf.ProducerInfoDisplayForm", form.xf.ProducerInfoDisplayForm)

// EOP
;/**
 * 用户所属用户组维护窗口
 * 
 * --------------------------------------------------------------
 * 消息：
 * 用户所属用户组有了变动
 * 
 * 消息名：     			
 * window.admin.UserGroupsChanged 
 * 
 * 消息内容：
 * {int} sender 当前组件Id
 * --------------------------------------------------------------
 * 
 */
window.admin.UserAndGroupWindow = Ext.extend(Ext.Window, {
	cancelAction : "hide",  //还可以取值：destroy
	closeAction : "hide",
	userId : null,
	userName : null,
	initComponent : function() {
		Ext.apply(this,{
			title : '选择所属用户组 - '+this.userName,
			width : 550,	
			height : 300,
			modal : true,
			closable : true,
			maximizable : false,
			minimizable : false,
			layout : "fit",
			buttons : [{
				text : "确定",
				handler : this.onSave,
				scope : this
			}, {
				text : "取消",
				handler : this.onCancel,
				scope : this
			}],
			items : {
				xtype : "form.admin.UserAndGroupForm",
				userId : this.userId
			}
		});
		
		window.admin.UserAndGroupWindow.superclass.initComponent.call(this);
	},
	onSave : function() {
		this.items.itemAt(0).save(this.onSaveSucccess.createDelegate(this))
	},
	onSaveSucccess : function() {
		this.close()
		this.publish("window.admin.UserGroupsChanged",{sender:this.id})
	}
});
// EOP

;/**
 * 企业会员用户所属用户组管理
 */
panel.xf.CorpUserGroupsGridPanel = Ext.extend(panel.admin.UserGroupsGridPanel, {
	//public
	//corpUserId 为 CorpUser 表的id;
	//msg 为 divo.rowSelect 消息
	showList : function(corpUserId,msg) {
	   if (msg && msg.record) {
	   	   this.userId = msg.record.data.user_id
		   this.corpUser = msg.record.data
	   }
	   
	   if (!this.userId) return
	   
	   this.setUrl("/users/"+this.userId+"/groups")
  	   this.loadList()
	},
	//重写
	selectUserGroups : function() {
		if (!this.validate()) {
			return
		}
		this.userAndGroupWindowId = this.myId('win')
		
		var win = new window.admin.UserAndGroupWindow({
			id : this.userAndGroupWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			userId : this.userId,
			userName : this.corpUser.corp_name
		})
		win.show()
	}
	
})

Ext.reg('panel.xf.CorpUserGroupsGridPanel', panel.xf.CorpUserGroupsGridPanel)
// EOP

;/**
 * 灭火器维修单位维护
 */
divo.xf.mainter.MainPanel = Ext.extend(Ext.Panel, {
	initComponent : function() {
		if (this.isCorpUser()) {
			alert("对不起，企业会员用户不能使用此功能。")
			divo.xf.mainter.MainPanel.superclass.initComponent.call(this)
			return
		}
		this.portletDefinitions = [{
			id : 'info',
			text : '企业资料',
			xtype : "form.xf.MainterInfoDisplayForm",
			config : {
			    menuItemId : this.menuItemId
			}
		},{
			id : 'actionlog',
			text : '操作日志',
			xtype : "panel.xf.ActionLogGridPanel",
			config : {
			    menuItemId : this.menuItemId,
			    actionCode : 4
			}
		}]
	
		this.mainterGridPanelId = this.myId("mainter")
		this.portalId = this.myId('portal')
		this.portalMgr = new Ext.ux.PortalManager(
			this.portalId,
			'xf-mainter-portal',
			this.portletDefinitions)
		
		Ext.apply(this, {
			layout : 'tdgi_border',
			defaults : {
				border : false
			},
			border : false,
			items : [{
				stateful : true,
				stateId : this.myId('mainter'),
				region : 'west',
				title : '灭火器维修单位一览',
				collapsible : false,
				ctCls : "j-toolbar-dark",
				width : 500,
				collapsedTitle : true,
				split : true,
				layout : 'fit',
				items : [{
					id : this.mainterGridPanelId,
					xtype : "panel.xf.MainterGridPanel",
					menuItemId : this.menuItemId
				}]
			}, {  
				region : 'center',
				layout : 'fit',
                tbar : this.portalMgr.getTbar(),
                autoScroll:true,
				ctCls : "j-toolbar-dark",
				items : [{
					xtype : 'statefulportal',
					id : this.portalId,
					items : [{
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}]
				}]
			}]	
		})

		this.subscribe("divo.rowSelect"+this.mainterGridPanelId,this.onMainterChange,this)

		divo.xf.mainter.MainPanel.superclass.initComponent.call(this)
	},
	onMainterChange : function(subj, msg, data) {
		this.portalMgr.onRefresh(msg)
	},
	initPortal : function() {
		if (!this.portalMgr) return
		this.portalMgr.init()

		Ext.ComponentMgr.get(this.portalId).on("drop", function() {
			this.portalMgr.saveState()
		},this)
	}
	
})

divo.xf.mainter.Main = function() {
	/* ----------------------- private变量 ----------------------- */
	var mp

	/* ----------------------- private方法 ----------------------- */
	// 创建布局
	function createLayout(parentPanel,menuItemId,extraInfo) {
		mp = new divo.xf.mainter.MainPanel({
			id : 'xf-mainter',
			menuItemId : menuItemId
		})
		parentPanel.add(mp)
		parentPanel.doLayout()
	}

	/* ----------------------- public方法 ----------------------- */
	return {

		// 初始化
		init : function(parentPanel, menuItemId,extraInfo) {
			createLayout(parentPanel,menuItemId,extraInfo)
			mp.initPortal()
		}

	} // return

}()
// EOP

;/**
 * 生产厂家网格面板
 */
panel.xf.MainterGridPanel = Ext.extend(divo.panel.SmartGridDetailPanel, {
	defaultViewCode : null,
	initComponent : function() {
 		this.action = new Ext.ux.grid.RowActions({
            header:'操作',
            autoWidth:false, 
            width:60,
            actions:[{
                iconCls:'icon-update',
                tooltip:'修改灭火器维修单位',
                hide : !this.canUpdate()
            },{
                iconCls:'icon-delete',
                tooltip:'删除灭火器维修单位',
                hide : !this.canDelete()
            }]
        })
		this.action.on('action',this.onAction,this)
	
		Ext.apply(this, {
			url : "/xf/mainters",
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				defaultViewCode : this.defaultViewCode,
				gridIdOfView : 'xf-mainter-grid', 
				filter : true,
				toolbar : this.isLookup?false:this.createToolbarBtn(),
				plugins : [this.action],
				autoExpandColumn : 'name'
			},
			autoScroll : true
		})
		
		this.subscribe("window.xf.MainterChanged", this.onMainterChanged, this)
		this.on('beforedestroy', function() {
			this.unsubscribe()
		}, this)
		
		panel.xf.MainterGridPanel.superclass.initComponent.apply(this,arguments)
	},
	onAction : function(grid, record, action, row, col) {
		if (action=='icon-update')
		    this.editItem()
		if (action=='icon-delete')
		    this.deleteItem()
	},
	//重写
	createGridMeta : function() {
		return this.getGridMeta(this.fieldDefinitions,this.isLookup?null:[this.action])
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		},{
			name : 'name',
			header : '企业名称',
			searchable : true,
			type : 'string',
			id : 'name'
		},{
			name : 'py',
			header : '拼音助记符',
			searchable : true,
			type : 'string'
		},{
			name : 'area_name',
			header : '地区',
			type : 'string'
		}]
	},
	createToolbarBtn : function(){
		var tb = [];

		var addBtn = new Ext.Toolbar.Button( {
			text : '新建',
			tooltip : '新建灭火器维修单位',
			icon : divo.iconAdd,
			cls : 'x-btn-text-icon',
			hidden : !this.canCreate(),
			handler : this.addItem.createDelegate(this)
		})
		tb.push(addBtn)
		return tb
	},
	addItem : function() {
		this.mainterWindowId = this.myId('win')

		var win = new window.xf.MainterAddOrEditWindow({
			id : this.mainterWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : true
		})
		win.show()
	},
	editItem : function() {
		if (!this.cId) {
			this.say("请先选择要修改的记录")
			return
		}
		this.mainterWindowId = this.myId('win')

		var win = new window.xf.MainterAddOrEditWindow({
			id : this.mainterWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : false,
			mainterId : this.cId
		})
		win.show()
	},
	onMainterChanged : function(subj, msg, data) {
		if (msg.sender == this.mainterWindowId) {
			this.cIdFocus = msg.id
			this.loadList()
		}
	},
	onLoadItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.fillForm(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
	},
	onDeleteItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'DELETE',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (resp.success)
					this.deleteItemCallback()
				else
				    this.sayError(resp.errors.reason) 
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	}

})

Ext.reg('panel.xf.MainterGridPanel', panel.xf.MainterGridPanel);
// EOP

;/**
 *灭火器维修单位新建或修改表单
 */
form.xf.MainterAddOrEditForm = Ext.extend(divo.form.AddOrEditForm, {
	initFocusFldName : 'name',
	mainterId : null,
	initComponent : function() {
		Ext.apply(this, {
			labelWidth : 280,
			defaultType : "textfield",
			labelAlign : "right",
			autoScroll : true,
			bodyStyle : "padding:10px",
			items : [{
				xtype : 'panel',
				border : false,
				bodyStyle : 'background:none;padding-bottom:10px',
				html : '带 (' + divo.required + ') 号栏位为必填项。'
			},{
				fieldLabel : divo.required+"企业名称",
				name : "name",
				width:300,
				listeners : {
					change : {
						scope : this,
						fn : function(o, value) {
							var py = Ext.getCmp(this.myId('py'))
							Ext.Ajax.request({
								scope : this,
								url : "/hz/pymemo",
								async : true,
								method : 'GET',
								params : {'name':o.getValue()}, 
								success : function(response, options) {
									var resp = Ext.decode(response.responseText)
									py.setValue(resp.hzpy)
								}
							})
						} //fn
					} //change
				} //listeners
			},{
				fieldLabel : "拼音助记符",
				name : "py",
				id : this.myId('py'),
				width : 300
			},{
				fieldLabel : divo.required+"维修证书号",
				name : "certificate_number",
				width:300
			}, {
				xtype : 'datefield',
				fieldLabel : divo.required + "维修证书有效期",
				name : 'certificate_date',
				format : 'Y.m.d',
				width : 100
			}, {
				xtype : 'combo',
				fieldLabel : divo.required + '所在地区',
				name : 'area_name',
				emptyText : '',
				mode : 'remote',
				editable : false,
				triggerAction : 'all',
				forceSelection : true,
				valueField : 'name',
				displayField : 'name',
				store : new Ext.data.Store({
					id : 'id',
					proxy : new Ext.data.HttpProxy({
						url : "/xf/areas",
						method : 'GET'
					}),
					reader : new Ext.data.JsonReader({
						root : 'rows',
						fields : ['id', 'name']
					})
				})
			}, {
				fieldLabel : divo.required+"法定代表人",
				name : "corporation",
				maxLength : 20,
				width:300
			},{
				fieldLabel : divo.required+"法定代表人电话",
				name : "corporation_tele",
				maxLength :40,
				width:300
			},{
				fieldLabel : divo.required+"主要负责人",
				name : "leader",
				maxLength : 20,
				width:300
			},{
				fieldLabel : divo.required+"主要负责人电话",
				name : "leader_tele",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"主要负责人手机号",
				name : "leader_mobile",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"单位电话号码",
				name : "tele",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"单位传真号码",
				name : "fax",
				maxLength : 40,
				width:300
			},{
				fieldLabel : divo.required+"邮编",
				name : "post_code",
				maxLength : 40,
				width:300
			},{
				fieldLabel : divo.required+"工商注册地址",
				name : "register_address",
				width:300
			},{
				fieldLabel : divo.required+"实际经营地址",
				name : "address",
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"注册资金(万元)",
				name : "register_money",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"员工人数",
				name : "employee_count",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"技术员工人数",
				name : "tech_count",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海消防协会消防产业委员会会员单位",
				items: [
                    {boxLabel: '是', name: 'is_member',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_member',inputValue: false}
                ]
			},{
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海市消防产业诚信承诺单位",
				items: [
                    {boxLabel: '是', name: 'is_trustful',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_trustful',inputValue: false}
                ]
			},{
				fieldLabel : "备注",
				name : "note",
				width:300
			}]
		})

		form.xf.MainterAddOrEditForm.superclass.initComponent.call(this);
	},
	//重写
    loadItem : function() {
		Ext.Ajax.request({
			scope : this,
			url : "/xf/mainters/"+this.mainterId,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.getForm().setValues(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
    },
	// public
	save : function(callbackOnSuccess) {
		var item = this.getForm().getObjectValues()
		item.is_member = eval(item.is_member)
		item.is_trustful = eval(item.is_trustful)
		item.is_recommended = eval(item.is_recommended)

		Ext.Ajax.request({
			scope : this,
			url : "/xf/mainters"+(this.adding?"":"/"+this.mainterId),
			waitMsg : "正在提交...",
			method : (this.adding?'POST':'PUT'),
			jsonData : item,
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (!resp.success) {
					this.getForm().markInvalid(resp.errors)
				} else {
					callbackOnSuccess(resp.id)
				}
			},
			failure : function(response, options) {
				this.alert(response.responseText)	
			}
		})
	}
})

Ext.reg("form.xf.MainterAddOrEditForm", form.xf.MainterAddOrEditForm)
// EOP

;/**
 * 灭火器维修单位新建或修改窗口
 *
 * --------------------------------------------------------------
 * 消息：
 * 灭火器维修单位新增或修改了
 * 
 * 消息名：     			
 * window.xf.MainterChanged    
 * 
 * 消息内容：
 * {int} sender 本组件的id值
 * --------------------------------------------------------------
 */
window.xf.MainterAddOrEditWindow = Ext.extend(Ext.Window, {
	cancelAction : "hide",  //还可以取值：destroy
	closeAction : "hide",
	adding : false,
	MainterId : null,
	initComponent : function() {
		Ext.apply(this,{
			title : (this.adding?'新建':'修改')+'灭火器维修单位',
			width : 670,
			height : 550,
			modal : true,
			stateful : true,
			stateId : 'xf-mainter-win',
			closable : true,
			maximizable : false,
			minimizable : false,
			layout : "fit",
			buttons : [{
				text : "确定",
				handler : this.onSave,
				scope : this
			}, {
				text : "取消",
				handler : this.onCancel,
				scope : this
			}],
			items : {
				xtype : "form.xf.MainterAddOrEditForm",
				adding : this.adding,
				mainterId : this.mainterId
			}
		});
		
		window.xf.MainterAddOrEditWindow.superclass.initComponent.call(this);
	},
	onSave : function() {
		this.items.itemAt(0).save(this.onSaveSucccess.createDelegate(this))
	},
	onSaveSucccess : function(id) {
		this.say(this.adding ? '新建成功, 请继续新建。':'修改已经保存')
		if (!this.adding)
		   this.close()
		else   
		   this.items.itemAt(0).clearForm()
		
		this.publish("window.xf.MainterChanged",{
			sender:this.id,
			id : id
		})
	}
});
// EOP

;/**
 * 产品生产单位维护
 */
divo.xf.producer.MainPanel = Ext.extend(Ext.Panel, {
	initComponent : function() {
		if (this.isCorpUser()) {
			alert("对不起，企业会员用户不能使用此功能。")
			divo.xf.producer.MainPanel.superclass.initComponent.call(this)
			return
		}
		this.portletDefinitions = [{
			id : 'info',
			text : '企业资料',
			xtype : "form.xf.ProducerInfoDisplayForm",
			config : {
			    menuItemId : this.menuItemId
			}
		},{
			id : 'actionlog',
			text : '操作日志',
			xtype : "panel.xf.ActionLogGridPanel",
			config : {
			    menuItemId : this.menuItemId,
			    actionCode : 1
			}
		}]
	
		this.producerGridPanelId = this.myId("producer")
		this.portalId = this.myId('portal')
		this.portalMgr = new Ext.ux.PortalManager(
			this.portalId,
			'xf-producer-portal',
			this.portletDefinitions)
		
		Ext.apply(this, {
			layout : 'tdgi_border',
			defaults : {
				border : false
			},
			border : false,
			items : [{
				stateful : true,
				stateId : this.myId('producer'),
				region : 'west',
				title : '产品生产单位一览',
				collapsible : false,
				ctCls : "j-toolbar-dark",
				width : 500,
				collapsedTitle : true,
				split : true,
				layout : 'fit',
				items : [{
					id : this.producerGridPanelId,
					xtype : "panel.xf.ProducerGridPanel",
					menuItemId : this.menuItemId
				}]
			}, {  
				region : 'center',
				layout : 'fit',
                tbar : this.portalMgr.getTbar(),
                autoScroll:true,
				ctCls : "j-toolbar-dark",
				items : [{
					xtype : 'statefulportal',
					id : this.portalId,
					items : [{
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}]
				}]
			}]	
		})

		this.subscribe("divo.rowSelect"+this.producerGridPanelId,this.onProducerChange,this)

		divo.xf.producer.MainPanel.superclass.initComponent.call(this)
	},
	onProducerChange : function(subj, msg, data) {
		this.portalMgr.onRefresh(msg)
	},
	initPortal : function() {
		if (!this.portalMgr) return
		this.portalMgr.init()

		Ext.ComponentMgr.get(this.portalId).on("drop", function() {
			this.portalMgr.saveState()
		},this)
	}
	
})

divo.xf.producer.Main = function() {
	/* ----------------------- private变量 ----------------------- */
	var mp

	/* ----------------------- private方法 ----------------------- */
	// 创建布局
	function createLayout(parentPanel,menuItemId,extraInfo) {
		mp = new divo.xf.producer.MainPanel({
			id : 'xf-producer',
			menuItemId : menuItemId
		})
		parentPanel.add(mp)
		parentPanel.doLayout()
	}

	/* ----------------------- public方法 ----------------------- */
	return {

		// 初始化
		init : function(parentPanel, menuItemId,extraInfo) {
			createLayout(parentPanel,menuItemId,extraInfo)
			mp.initPortal()
		}

	} // return

}()
// EOP

;/**
 * 生产厂家网格面板
 */
panel.xf.ProducerGridPanel = Ext.extend(divo.panel.SmartGridDetailPanel, {
	defaultViewCode : null,
	initComponent : function() {
 		this.action = new Ext.ux.grid.RowActions({
            header:'操作',
            autoWidth:false, 
            width:60,
            actions:[{
                iconCls:'icon-update',
                tooltip:'修改生产厂家',
                hide : !this.canUpdate()
            },{
                iconCls:'icon-delete',
                tooltip:'删除生产厂家',
                hide : !this.canDelete()
            }]
        })
		this.action.on('action',this.onAction,this)
	
		Ext.apply(this, {
			url : "/xf/producers",
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				defaultViewCode : this.defaultViewCode,
				gridIdOfView : 'xf-producer-grid', 
				filter : true,
				toolbar : this.isLookup?false:this.createToolbarBtn(),
				plugins : [this.action],
				autoExpandColumn : 'name'
			},
			autoScroll : true
		})
		
		this.subscribe("window.xf.ProducerChanged", this.onProducerChanged, this)
		this.on('beforedestroy', function() {
			this.unsubscribe()
		}, this)
		
		panel.xf.ProducerGridPanel.superclass.initComponent.apply(this,arguments)
	},
	onAction : function(grid, record, action, row, col) {
		if (action=='icon-update')
		    this.editItem()
		if (action=='icon-delete')
		    this.deleteItem()
	},
	//重写
	createGridMeta : function() {
		return this.getGridMeta(this.fieldDefinitions,this.isLookup?null:[this.action])
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		},{
			name : 'name',
			header : '企业名称',
			searchable : true,
			type : 'string',
			id : 'name'
		},{
			name : 'py',
			header : '拼音助记符',
			searchable : true,
			type : 'string'
		},{
			name : 'area_name',
			header : '地区',
			searchable : true,
			type : 'string'
		}]
	},
	createToolbarBtn : function(){
		var tb = [];

		var addBtn = new Ext.Toolbar.Button( {
			text : '新建',
			tooltip : '新建生产厂家',
			icon : divo.iconAdd,
			cls : 'x-btn-text-icon',
			hidden : !this.canCreate(),
			handler : this.addItem.createDelegate(this)
		})
		tb.push(addBtn)
		return tb
	},
	addItem : function() {
		this.producerWindowId = this.myId('win')

		var win = new window.xf.ProducerAddOrEditWindow({
			id : this.producerWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : true
		})
		win.show()
	},
	editItem : function() {
		if (!this.cId) {
			this.say("请先选择要修改的记录")
			return
		}
		this.producerWindowId = this.myId('win')

		var win = new window.xf.ProducerAddOrEditWindow({
			id : this.producerWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : false,
			producerId : this.cId
		})
		win.show()
	},
	onProducerChanged : function(subj, msg, data) {
		if (msg.sender == this.producerWindowId) {
			this.cIdFocus = msg.id
			this.loadList()
		}
	},
	onLoadItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.fillForm(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
	},
	onDeleteItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'DELETE',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (resp.success)
					this.deleteItemCallback()
				else
				    this.sayError(resp.errors.reason) 
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	}

})

Ext.reg('panel.xf.ProducerGridPanel', panel.xf.ProducerGridPanel);
// EOP

;/**
 *生产厂家新建或修改表单
 */
form.xf.ProducerAddOrEditForm = Ext.extend(divo.form.AddOrEditForm, {
	initFocusFldName : 'name',
	producerId : null,
	initComponent : function() {
		Ext.apply(this, {
			labelWidth : 280,
			defaultType : "textfield",
			labelAlign : "right",
			autoScroll : true,
			bodyStyle : "padding:10px",
			items : [{
				xtype : 'panel',
				border : false,
				bodyStyle : 'background:none;padding-bottom:10px',
				html : '带 (' + divo.required + ') 号栏位为必填项。'
			},{
				fieldLabel : divo.required+"企业名称",
				name : "name",
				width:300,
				listeners : {
					change : {
						scope : this,
						fn : function(o, value) {
							var py = Ext.getCmp(this.myId('py'))
							Ext.Ajax.request({
								scope : this,
								url : "/hz/pymemo",
								async : true,
								method : 'GET',
								params : {'name':o.getValue()}, 
								success : function(response, options) {
									var resp = Ext.decode(response.responseText)
									py.setValue(resp.hzpy)
								}
							})
						} //fn
					} //change
				} //listeners
			}, {
				fieldLabel : "拼音助记符",
				name : "py",
				id : this.myId('py'),
				width : 300
			}, {
				xtype : 'combo',
				fieldLabel : divo.required + '所在地区',
				name : 'area_name',
				emptyText : '',
				mode : 'remote',
				editable : false,
				triggerAction : 'all',
				forceSelection : true,
				valueField : 'name',
				displayField : 'name',
				store : new Ext.data.Store({
					id : 'id',
					proxy : new Ext.data.HttpProxy({
						url : "/xf/areas",
						method : 'GET'
					}),
					reader : new Ext.data.JsonReader({
						root : 'rows',
						fields : ['id', 'name']
					})
				})
			}, {
				fieldLabel : divo.required+"法定代表人",
				name : "corporation",
				maxLength : 20,
				width:300
			},{
				fieldLabel : divo.required+"法定代表人电话",
				name : "corporation_tele",
				maxLength :40,
				width:300
			},{
				fieldLabel : divo.required+"主要负责人",
				name : "leader",
				maxLength : 20,
				width:300
			},{
				fieldLabel : divo.required+"主要负责人电话",
				name : "leader_tele",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"主要负责人手机号",
				name : "leader_mobile",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"单位电话号码",
				name : "tele",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"单位传真号码",
				name : "fax",
				maxLength : 40,
				width:300
			},{
				fieldLabel : divo.required+"邮编",
				name : "post_code",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"工商注册地址",
				name : "register_address",
				width:300
			},{
				fieldLabel : divo.required+"实际经营地址",
				name : "address",
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"注册资金(万元)",
				name : "register_money",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"员工人数",
				name : "employee_count",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"技术员工人数",
				name : "tech_count",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海消防协会消防产业委员会会员单位",
				items: [
                    {boxLabel: '是', name: 'is_member',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_member',inputValue: false}
                ]
			},{
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海市消防产业诚信承诺单位",
				items: [
                    {boxLabel: '是', name: 'is_trustful',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_trustful',inputValue: false}
                ]
			},{
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海市消防行业推荐产品单位",
				items: [
                    {boxLabel: '是', name: 'is_recommended',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_recommended',inputValue: false}
                ]
			},{
				fieldLabel : "备注",
				name : "note",
				width:300
			}]
		})
		form.xf.ProducerAddOrEditForm.superclass.initComponent.call(this);
	},
	//重写
    loadItem : function() {
		Ext.Ajax.request({
			scope : this,
			url : "/xf/producers/"+this.producerId,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.getForm().setValues(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
    },
	// public
	save : function(callbackOnSuccess) {
		var item = this.getForm().getObjectValues()
		item.is_member = eval(item.is_member)
		item.is_trustful = eval(item.is_trustful)
		item.is_recommended = eval(item.is_recommended)

		Ext.Ajax.request({
			scope : this,
			url : "/xf/producers"+(this.adding?"":"/"+this.producerId),
			waitMsg : "正在提交...",
			method : (this.adding?'POST':'PUT'),
			jsonData : item,
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (!resp.success) {
					this.getForm().markInvalid(resp.errors)
				} else {
					callbackOnSuccess(resp.id)
				}
			},
			failure : function(response, options) {
				this.alert(response.responseText)	
			}
		})
	}
})

Ext.reg("form.xf.ProducerAddOrEditForm", form.xf.ProducerAddOrEditForm)
// EOP

;/**
 * 生产厂家新建或修改窗口
 *
 * --------------------------------------------------------------
 * 消息：
 * 生产厂家新增或修改了
 * 
 * 消息名：     			
 * window.xf.ProducerChanged    
 * 
 * 消息内容：
 * {int} sender 本组件的id值
 * --------------------------------------------------------------
 */
window.xf.ProducerAddOrEditWindow = Ext.extend(Ext.Window, {
	cancelAction : "hide",  //还可以取值：destroy
	closeAction : "hide",
	adding : false,
	producerId : null,
	initComponent : function() {
		Ext.apply(this,{
			title : (this.adding?'新建':'修改')+' 生产厂家',
			width : 670,
			height : 550,
			modal : true,
			stateful : true,
			stateId : 'xf-producer-win',
			closable : true,
			maximizable : false,
			minimizable : false,
			layout : "fit",
			buttons : [{
				text : "确定",
				handler : this.onSave,
				scope : this
			}, {
				text : "取消",
				handler : this.onCancel,
				scope : this
			}],
			items : {
				xtype : "form.xf.ProducerAddOrEditForm",
				adding : this.adding,
				producerId : this.producerId
			}
		});
		
		window.xf.ProducerAddOrEditWindow.superclass.initComponent.call(this);
	},
	onSave : function() {
		this.items.itemAt(0).save(this.onSaveSucccess.createDelegate(this))
	},
	onSaveSucccess : function(id) {
		this.say(this.adding ? '新建成功, 请继续新建。':'修改已经保存')
		if (!this.adding)
		   this.close()
		else   
		   this.items.itemAt(0).clearForm()
		
		this.publish("window.xf.ProducerChanged",{
			sender:this.id,
			id : id
		})
	}
});
// EOP

;/**
 * 消防产品维护
 */
divo.xf.product.MainPanel = Ext.extend(Ext.Panel, {
	initComponent : function() {
		this.portletDefinitions = [{
			id : 'info',
			text : '产品资料',
			xtype : "form.xf.ProductDisplayForm",
			config : {
			    menuItemId : this.menuItemId
			}
		},{
			id : 'actionlog',
			text : '操作日志',
			xtype : "panel.xf.ActionLogGridPanel",
			config : {
			    menuItemId : this.menuItemId,
			    actionCode : 5
			}
		}]
	
		this.productGridPanelId = this.myId("product")
		this.portalId = this.myId('portal')
		this.portalMgr = new Ext.ux.PortalManager(
			this.portalId,
			'xf-product-portal',
			this.portletDefinitions)
		
		Ext.apply(this, {
			layout : 'tdgi_border',
			defaults : {
				border : false
			},
			border : false,
			items : [{
				stateful : true,
				stateId : this.myId('product'),
				region : 'west',
				title : '消防产品一览',
				collapsible : false,
				ctCls : "j-toolbar-dark",
				width : 600,
				collapsedTitle : true,
				split : true,
				layout : 'fit',
				items : [{
					id : this.productGridPanelId,
					xtype : "panel.xf.ProductGridPanel",
					menuItemId : this.menuItemId
				}]
			}, {  
				region : 'center',
				layout : 'fit',
                tbar : this.portalMgr.getTbar(),
                autoScroll:true,
				ctCls : "j-toolbar-dark",
				items : [{
					xtype : 'statefulportal',
					id : this.portalId,
					items : [{
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}]
				}]
			}]	
		})

		this.subscribe("divo.rowSelect"+this.productGridPanelId,this.onProducerChange,this)

		divo.xf.product.MainPanel.superclass.initComponent.call(this)
	},
	onProducerChange : function(subj, msg, data) {
		this.portalMgr.onRefresh(msg)
	},
	initPortal : function() {
		this.portalMgr.init()

		Ext.ComponentMgr.get(this.portalId).on("drop", function() {
			this.portalMgr.saveState()
		},this)
	}
	
})

divo.xf.product.Main = function() {
	/* ----------------------- private变量 ----------------------- */
	var mp

	/* ----------------------- private方法 ----------------------- */
	// 创建布局
	function createLayout(parentPanel,menuItemId,extraInfo) {
		mp = new divo.xf.product.MainPanel({
			id : 'xf-product',
			menuItemId : menuItemId
		})
		parentPanel.add(mp)
		parentPanel.doLayout()
	}

	/* ----------------------- public方法 ----------------------- */
	return {

		// 初始化
		init : function(parentPanel, menuItemId,extraInfo) {
			createLayout(parentPanel,menuItemId,extraInfo)
			mp.initPortal()
		}

	} // return

}()
// EOP

;/**
 * 消防产品网格面板
 */
panel.xf.ProductGridPanel = Ext.extend(divo.panel.SmartGridDetailPanel, {
	initComponent : function() {
		this.action = new Ext.ux.grid.RowActions({
			header : '操作',
			autoWidth : false,
			width : 60,
			actions : [{
				iconCls : 'icon-update',
				tooltip : '修改消防产品',
				hide : !this.canUpdate()
			}, {
				iconCls : 'icon-delete',
				tooltip : '删除消防产品',
				hide : !this.canDelete()
			}]
		})
		this.action.on('action', this.onAction, this)

		Ext.apply(this, {
			url : "/xf/products",
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				gridIdOfView : 'xf-product-grid',
				filter : true,
				toolbar : this.isLookup ? false : this.createToolbarBtn(),
				plugins : [this.action],
				autoExpandColumn : 'name'
			},
			autoScroll : true
		})

		this.subscribe("window.xf.ProductChanged", this.onProductChanged, this)
		this.on('beforedestroy', function() {
			this.unsubscribe()
		}, this)

		panel.xf.ProductGridPanel.superclass.initComponent.apply(this,
				arguments)
	},
	onAction : function(grid, record, action, row, col) {
		if (action == 'icon-update')
			this.editItem()
		if (action == 'icon-delete')
			this.deleteItem()
	},
	// 重写
	createGridMeta : function() {
		return this.getGridMeta(this.fieldDefinitions,this.isLookup?null:[this.action])
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		}, {
			name : 'name',
			header : '名称',
			searchable : true,
			type : 'string',
			id : 'name'
		}, {
			name : 'spec',
			header : '型号',
			type : 'string'
		},{
			name : 'py',
			header : '拼音助记符',
			searchable : true,
			type : 'string'
		}, {
			name : 'producer_name',
			header : '生产厂家',
			type : 'string',
			sortable : false,
			id : 'producer_name'
		}]
	},
	// 添加工具条按钮
	createToolbarBtn : function() {
		var tb = [];

		var addBtn = new Ext.Toolbar.Button({
			text : '新建',
			tooltip : '新建消防产品',
			icon : divo.iconAdd,
			cls : 'x-btn-text-icon',
			hidden : !this.canCreate(),
			handler : this.addItem.createDelegate(this)
		})
		tb.push(addBtn)
		return tb
	},
	addItem : function() {
		this.productWindowId = this.myId('win')

		var win = new window.xf.ProductAddOrEditWindow({
			id : this.productWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : true,
			productStatus : 2
		})
		win.show()
	},
	editItem : function() {
		if (!this.cId) {
			this.say("请先选择要修改的记录")
			return
		}
		this.productWindowId = this.myId('win')

		var win = new window.xf.ProductAddOrEditWindow({
			id : this.productWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : false,
			productId : this.cId
		})
		win.show()
	},
	onProductChanged : function(subj, msg, data) {
		if (msg.sender == this.productWindowId) {
			this.cIdFocus = msg.id
			this.loadList()
		}
	},
	onDeleteItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url + '/' + id,
			method : 'DELETE',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (resp.success)
					this.deleteItemCallback()
				else
					this.say(resp.errors.reason)
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	}

})

Ext.reg('panel.xf.ProductGridPanel', panel.xf.ProductGridPanel);
// EOP

;/**
 * 消防产品新建或修改表单
 */
form.xf.ProductAddOrEditForm = Ext.extend(divo.form.AddOrEditForm, {
	initFocusFldName : 'name',
	productId : null,
	productStatus : null, //0-新登记未提交审核 1-已提交审核等待审批 2-已经审核通过
	initComponent : function() {
		if (this.isProducerUser())
			this.corpInfo = this.getCorpInfo()
		var lovDisplay = [divo.t1 + '{name}' + divo.t2].join('');
		this.producerFld = {
			xtype : 'xlovfield',
			name : 'producer_id',
			fieldLabel : divo.required + '生产厂家',
			allowBlank : true,
			multiSelect : false,
			lovTitle : '请选择',
			lovHeight : 350,
			lovWidth : 550,
			minItem : 1,
			maxItem : 1,
			width : 300,
			valueField : 'id',
			displayField : lovDisplay,
			textarea : false,
			view : new panel.xf.ProducerGridPanel({
				isLookup : true
			})
		}
		var catReader = new Ext.data.JsonReader({
				totalProperty : 'totalCount',
				root : 'rows',
				id : 'id'
			}, [{
				name : 'tree_code'
			},{
				name : 'name'
			}])
		var cat1Store = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : '/xf/productcats/level1',
				method : 'GET'
			}),
			reader : catReader,
			autoLoad : true
		})
		if (!this.adding)
			cat1Store.on("load", function() {
				 this.afterCat1ComboLoad()
			}, this, true)
		var cat2Store = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				method : 'GET'
			}),
			reader : catReader,
			autoLoad : false
		})
		cat2Store.on("load", function() {
			 this.afterCat2ComboLoad()
		}, this, true)
		var list1 = [{
				xtype : 'panel',
				border : false,
				bodyStyle : 'background:none;padding-bottom:10px'
			}, {
				fieldLabel : "产品名称",
				name : "name",
				width : 300,
				listeners : {
					change : {
						scope : this,
						fn : function(o, value) {
							var py = Ext.getCmp(this.myId('py'))
							Ext.Ajax.request({
								scope : this,
								url : "/hz/pymemo",
								async : true,
								method : 'GET',
								params : {'name':o.getValue()}, 
								success : function(response, options) {
									var resp = Ext.decode(response.responseText)
									py.setValue(resp.hzpy)
								}
							})
						} //fn
					} //change
				} //listeners
			}, {
				fieldLabel : "产品型号",
				name : "spec",
				width : 300
			}, {
				fieldLabel : "拼音助记符",
				name : "py",
				id : this.myId('py'),
				width : 300
			}, {
				fieldLabel : "计量单位",
				name : "unit_name",
				width : 100
			}, new Ext.form.ComboBox({
				name : 'cat_code_1',
				fieldLabel : '一级分类',
				displayField : 'name',
				valueField : 'tree_code',
				hiddenName : 'cat_code_1',
				id : this.myId('cat1'),
				store : cat1Store,
				triggerAction : 'all',
				mode : 'local',
				editable : false,
				listeners : {
					select : {
						scope : this,
						fn : function(combo, value) {
							var cat2Combo = Ext.getCmp(this.myId('cat2'))
							cat2Combo.setValue('')
							cat2Combo.setDisabled(false)
							cat2Combo.store.proxy.conn.url = "/xf/productcats/childs/"+combo.getValue()
							cat2Combo.store.reload()
						}
					}
				}
			}), new Ext.form.ComboBox({
				name : 'cat_code_2',
				fieldLabel : '二级分类',
				displayField : 'name',
				valueField : 'tree_code',
				hiddenName : 'cat_code_2',
				id : this.myId('cat2'),
				disabled : this.adding,
				editable : false,
				store : cat2Store,
				triggerAction : 'all',
				mode : 'local',
				autoHeight : true
			})]
		var list2 = [{
				fieldLabel : "商标",
				name : 'brand',
				width : 300
			}, {
				xtype : "radiogroup",
				width : 240,
				fieldLabel : "认证类别",
				items: [
                    {boxLabel: '3C认证', name: 'auth_type',inputValue: '3C认证', checked: true},
                    {boxLabel: '型式认证', name: 'auth_type',inputValue: '型式认证'},
                    {boxLabel: '型式检验', name: 'auth_type',inputValue: '型式检验'}
                ]
			},{
				fieldLabel : "认证编号",
				name : 'auth_code',
				maxLength : 20,
				width : 180
			}, {
				xtype : 'datefield',
				fieldLabel : "认证有效期(截止日期)",
				name : 'end_date',
				format : 'Y.m.d',
				width : 100
			}, {
				xtype : 'datefield',
				fieldLabel : "报告签发日期",
				name : 'report_date',
				format : 'Y.m.d',
				width : 100
			}, {
				fieldLabel : "验证报告编号",
				name : 'report_code',
				maxLength : 20,
				width : 180
			}, {
				xtype : 'datefield',
				fieldLabel : "发换证日期",
				name : 'change_report_date',
				format : 'Y.m.d',
				width : 100
			}]
			
		var list3 = [this.producerFld]
		//登记新产品时不需要输入生产厂家
		var list = this.productStatus==0?list1.concat(list2):list1.concat(list3.concat(list2))
			
		Ext.apply(this, {
			labelWidth : 170,
			defaultType : "textfield",
			labelAlign : "right",
			autoScroll : true,
			bodyStyle : "padding:10px",
			items : list
		})
		form.xf.ProductAddOrEditForm.superclass.initComponent.call(this);
	},
	//重写
	loadItem : function() {
		Ext.Ajax.request({
			scope : this,
			url : "/xf/products/" + this.productId,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.getForm().setValues(resp.data)
				this.productStatus = resp.data.status

				var fld = this.getForm().findField("producer_id")
				if (fld)
					fld.setNameValue(resp.data.producer_name,resp.data.producer_id)
				
				this.cat_code1 = resp.data.cat_code_1
				this.cat_code2 = resp.data.cat_code_2
				
				var cat2Combo = Ext.getCmp(this.myId('cat2'))
				cat2Combo.store.proxy.conn.url = "/xf/productcats/childs/"+resp.data.cat_code_1
				cat2Combo.store.reload()
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
	},
	// public
	save : function(callbackOnSuccess) {
		var item = this.getForm().getObjectValues()
		item.status = this.productStatus
		if (this.productStatus==0)
			item.producer_id = this.corpInfo.id + ''
		
		var cat1Combo = Ext.getCmp(this.myId('cat1'))
		var cat2Combo = Ext.getCmp(this.myId('cat2'))
	    item.cat_name_1 = cat1Combo.el.dom.value
	    item.cat_name_2 = cat2Combo.el.dom.value

		Ext.Ajax.request({
			scope : this,
			url : "/xf/products" + (this.adding ? "" : "/" + this.productId),
			waitMsg : "正在提交...",
			method : (this.adding ? 'POST' : 'PUT'),
			jsonData : item,
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (!resp.success) {
					this.getForm().markInvalid(resp.errors)
				} else {
					callbackOnSuccess(resp.id)
				}
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	},
	afterCat1ComboLoad : function() {
		if (!this.cat_code1) return
		
		var cat1Combo = Ext.getCmp(this.myId('cat1'))
		var i = cat1Combo.store.find("tree_code",this.cat_code1)
		var r = cat1Combo.store.getAt(i)
		cat1Combo.setValue(r.data.name)
	},		
	afterCat2ComboLoad : function() {
		var cat2Combo = Ext.getCmp(this.myId('cat2'))
		if (this.adding) {
            if (cat2Combo.store.getCount()==1) {
				var r = cat2Combo.store.getAt(0)
				cat2Combo.setValue(r.data.name)
			}
			return
		}
		var i = cat2Combo.store.find("tree_code",this.cat_code2)
		var r = cat2Combo.store.getAt(i)
		cat2Combo.setValue(r.data.name)
	}
})

Ext.reg("form.xf.ProductAddOrEditForm", form.xf.ProductAddOrEditForm)
// EOP

;/**
 * 产品新建或修改窗口
 *
 * --------------------------------------------------------------
 * 消息：
 * 产品新增或修改了
 * 
 * 消息名：     			
 * window.xf.ProductChanged    
 * 
 * 消息内容：
 * {int} sender 本组件的id值
 * {int} id 新建或修改的记录id值
 * --------------------------------------------------------------
 */
window.xf.ProductAddOrEditWindow = Ext.extend(Ext.Window, {
	cancelAction : "hide",  //还可以取值：destroy
	closeAction : "hide",
	adding : false,
	productId : null,
	productStatus : null,
	initComponent : function() {
		var btns = [{
				text : "保存并继续",
				handler : this.onSave,
				scope : this
			}, {
				text : "保存并关闭",
				handler : this.onSaveAndClose,
				
				scope : this
			}, {
				text : "关闭",
				handler : this.onCancel,
				scope : this
			}]
		if (!this.adding)
			btns = [{
				text : "保存并关闭",
				handler : this.onSaveAndClose,
				scope : this
			}, {
				text : "关闭",
				handler : this.onCancel,
				scope : this
			}]
		Ext.apply(this,{
			title : (this.adding?'新建':'修改')+' 消防产品',
			width : 580,
			height : 520,
			modal : true,
			stateful : true,
			stateId : 'xf-product-win',
			closable : true,
			maximizable : false,
			minimizable : false,
			layout : "fit",
			buttons : btns,
			items : {
				xtype : "form.xf.ProductAddOrEditForm",
				adding : this.adding,
				productId : this.productId,
				productStatus : this.productStatus
			}
		})
		
		window.xf.ProductAddOrEditWindow.superclass.initComponent.call(this);
	},
	onSave : function() {
		this.items.itemAt(0).save(this.onSaveSucccess.createDelegate(this))
	},
	onSaveSucccess : function(id) {
		this.say(this.adding ? '新建成功, 请继续新建。':'修改已经保存')
		if (!this.adding)
		   this.close()
		else   
		   this.items.itemAt(0).clearForm()
		
		this.publish("window.xf.ProductChanged",{
			sender:this.id,
			id : id
		})
	},
	onSaveAndClose : function() {
		this.items.itemAt(0).save(this.onSaveAndCloseSucccess.createDelegate(this))
	},
	onSaveAndCloseSucccess : function(id) {
		this.say(this.adding ? '新建成功':'修改已经保存')
		this.close()
		
		this.publish("window.xf.ProductChanged",{
			sender:this.id,
			id : id
		})
	}
	
});
// EOP

;/**
 * 工程施工单位维护
 */
divo.xf.projecter.MainPanel = Ext.extend(Ext.Panel, {
	initComponent : function() {
		if (this.isCorpUser()) {
			alert("对不起，企业会员用户不能使用此功能。")
			divo.xf.producer.MainPanel.superclass.initComponent.call(this)
			return
		}
		this.portletDefinitions = [{
			id : 'info',
			text : '企业资料',
			xtype : "form.xf.ProjecterInfoDisplayForm",
			config : {
			    menuItemId : this.menuItemId
			}
		},{
			id : 'actionlog',
			text : '操作日志',
			xtype : "panel.xf.ActionLogGridPanel",
			config : {
			    menuItemId : this.menuItemId,
			    actionCode : 2
			}
		}]
	
		this.projecterGridPanelId = this.myId("projecter")
		this.portalId = this.myId('portal')
		this.portalMgr = new Ext.ux.PortalManager(
			this.portalId,
			'xf-projecter-portal',
			this.portletDefinitions)
		
		Ext.apply(this, {
			layout : 'tdgi_border',
			defaults : {
				border : false
			},
			border : false,
			items : [{
				stateful : true,
				stateId : this.myId('projecter'),
				region : 'west',
				title : '工程施工单位一览',
				collapsible : false,
				ctCls : "j-toolbar-dark",
				width : 500,
				collapsedTitle : true,
				split : true,
				layout : 'fit',
				items : [{
					id : this.projecterGridPanelId,
					xtype : "panel.xf.ProjecterGridPanel",
					menuItemId : this.menuItemId
				}]
			}, {  
				region : 'center',
				layout : 'fit',
                tbar : this.portalMgr.getTbar(),
                autoScroll:true,
				ctCls : "j-toolbar-dark",
				items : [{
					xtype : 'statefulportal',
					id : this.portalId,
					items : [{
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}, {
						columnWidth : .25,
						style : 'padding:10px 0 10px 10px'
					}]
				}]
			}]	
		})

		this.subscribe("divo.rowSelect"+this.projecterGridPanelId,this.onProjecterChange,this)

		divo.xf.projecter.MainPanel.superclass.initComponent.call(this)
	},
	onProjecterChange : function(subj, msg, data) {
		this.portalMgr.onRefresh(msg)
	},
	initPortal : function() {
		if (!this.portalMgr) return
		this.portalMgr.init()

		Ext.ComponentMgr.get(this.portalId).on("drop", function() {
			this.portalMgr.saveState()
		},this)
	}
	
})

divo.xf.projecter.Main = function() {
	/* ----------------------- private变量 ----------------------- */
	var mp

	/* ----------------------- private方法 ----------------------- */
	// 创建布局
	function createLayout(parentPanel,menuItemId,extraInfo) {
		mp = new divo.xf.projecter.MainPanel({
			id : 'xf-projecter',
			menuItemId : menuItemId
		})
		parentPanel.add(mp)
		parentPanel.doLayout()
	}

	/* ----------------------- public方法 ----------------------- */
	return {

		// 初始化
		init : function(parentPanel, menuItemId,extraInfo) {
			createLayout(parentPanel,menuItemId,extraInfo)
			mp.initPortal()
		}

	} // return

}()
// EOP

;/**
 * 工程施工单位网格面板
 */
panel.xf.ProjecterGridPanel = Ext.extend(divo.panel.SmartGridDetailPanel, {
	initComponent : function() {
 		this.action = new Ext.ux.grid.RowActions({
            header:'操作',
            autoWidth:false, 
            width:60,
            actions:[{
                iconCls:'icon-update',
                tooltip:'修改工程施工单位',
                hide : !this.canUpdate()
            },{
                iconCls:'icon-delete',
                tooltip:'删除工程施工单位',
                hide : !this.canDelete()
            }]
        })
		this.action.on('action',this.onAction,this)
	
		Ext.apply(this, {
			url : "/xf/projecters",
			fieldDefinitions : this.getListDefinitions(),
			gridConfig : {
				gridIdOfView : 'xf-projecter-grid', 
				filter : true,
				toolbar : this.isLookup?false:this.createToolbarBtn(),
				plugins : [this.action],
				autoExpandColumn : 'name'
			},
			autoScroll : true
		})
		
		this.subscribe("window.xf.ProjecterChanged", this.onProjecterChanged, this)
		this.on('beforedestroy', function() {
			this.unsubscribe()
		}, this)
		
		panel.xf.ProjecterGridPanel.superclass.initComponent.apply(this,arguments)
	},
	onAction : function(grid, record, action, row, col) {
		if (action=='icon-update')
		    this.editItem()
		if (action=='icon-delete')
		    this.deleteItem()
	},
	//重写
	createGridMeta : function() {
		return this.getGridMeta(this.fieldDefinitions,this.isLookup?null:[this.action])
	},
	getListDefinitions : function() {
		return [{
			name : 'id'
		},{
			name : 'project_grade'
		},{
			name : 'name',
			header : '企业名称',
			searchable : true,
			type : 'string',
			id : 'name'
		},{
			name : 'py',
			header : '拼音助记符',
			searchable : true,
			type : 'string'
		},{
			name : 'area_name',
			header : '地区',
			type : 'string'
		}]
	},
	createToolbarBtn : function(){
		var tb = [];

		var addBtn = new Ext.Toolbar.Button( {
			text : '新建',
			tooltip : '新建工程施工单位',
			icon : divo.iconAdd,
			cls : 'x-btn-text-icon',
			hidden : !this.canCreate(),
			handler : this.addItem.createDelegate(this)
		})
		tb.push(addBtn)
		return tb
	},
	addItem : function() {
		this.projecterWindowId = this.myId('win')

		var win = new window.xf.ProjecterAddOrEditWindow({
			id : this.projecterWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : true
		})
		win.show()
	},
	editItem : function() {
		if (!this.cId) {
			this.say("请先选择要修改的记录")
			return
		}
		this.projecterWindowId = this.myId('win')

		var win = new window.xf.ProjecterAddOrEditWindow({
			id : this.projecterWindowId,
			closeAction : "destroy",
			cancelAction : "destroy",
			adding : false,
			projecterId : this.cId
		})
		win.show()
	},
	onProjecterChanged : function(subj, msg, data) {
		if (msg.sender == this.projecterWindowId) {
			this.cIdFocus = msg.id
			this.loadList()
		}
	},
	onLoadItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.fillForm(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
	},
	onDeleteItem : function(id) {
		Ext.Ajax.request({
			scope : this,
			url : this.url+'/'+id,
			method : 'DELETE',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (resp.success)
					this.deleteItemCallback()
				else
				    this.sayError(resp.errors.reason) 
			},
			failure : function(response, options) {
				this.alert(response.responseText)
			}
		})
	}

})

Ext.reg('panel.xf.ProjecterGridPanel', panel.xf.ProjecterGridPanel);
// EOP

;/**
 *工程施工单位新建或修改表单
 */
form.xf.ProjecterAddOrEditForm = Ext.extend(divo.form.AddOrEditForm, {
	initFocusFldName : 'name',
	projecterId : null,
	initComponent : function() {
		Ext.apply(this, {
			labelWidth : 280,
			defaultType : "textfield",
			labelAlign : "right",
			autoScroll : true,
			bodyStyle : "padding:10px",
			items : [{
				xtype : 'panel',
				border : false,
				bodyStyle : 'background:none;padding-bottom:10px',
				html : '带 (' + divo.required + ') 号栏位为必填项。'
			},{
				fieldLabel : divo.required+"企业名称",
				name : "name",
				width:300,
				listeners : {
					change : {
						scope : this,
						fn : function(o, value) {
							var py = Ext.getCmp(this.myId('py'))
							Ext.Ajax.request({
								scope : this,
								url : "/hz/pymemo",
								async : true,
								method : 'GET',
								params : {'name':o.getValue()}, 
								success : function(response, options) {
									var resp = Ext.decode(response.responseText)
									py.setValue(resp.hzpy)
								}
							})
						} //fn
					} //change
				} //listeners
			},{
				fieldLabel : "拼音助记符",
				name : "py",
				id : this.myId('py'),
				width : 300
			},{
				fieldLabel : divo.required+"资质证书编号",
				name : "qualification_number",
				width:300
			},{
				xtype : "radiogroup",
				fieldLabel : "工程资质等级",
				width:320,
				items: [
                    {boxLabel: '一级', name: 'project_grade',inputValue: '一级', checked: true},
                    {boxLabel: '二级', name: 'project_grade',inputValue: '二级'},
                    {boxLabel: '三级', name: 'project_grade',inputValue: '三级'},
                    {boxLabel: '临时', name: 'project_grade',inputValue: '临时'}
                ]
			},{
				xtype : "radiogroup",
				fieldLabel : "消防专业承包资质等级",
				width:320,
				items: [
                    {boxLabel: '一级', name: 'specialty_grade',inputValue: '一级', checked: true},
                    {boxLabel: '二级', name: 'specialty_grade',inputValue: '二级'},
                    {boxLabel: '三级', name: 'specialty_grade',inputValue: '三级'},
                    {boxLabel: '临时', name: 'specialty_grade',inputValue: '临时'}
                ]
			},{
				xtype : "radiogroup",
				fieldLabel : "消防设计资质等级",
				width:240,
				items: [
                    {boxLabel: '一级', name: 'design_grade',inputValue: '一级', checked: true},
                    {boxLabel: '二级', name: 'design_grade',inputValue: '二级'},
                    {boxLabel: '没有', name: 'design_grade',inputValue: '没有'}
                ]
			},{
				xtype : 'combo',
				fieldLabel : divo.required + '所在地区',
				name : 'area_name',
				emptyText : '',
				mode : 'remote',
				editable : false,
				triggerAction : 'all',
				forceSelection : true,
				valueField : 'name',
				displayField : 'name',
				store : new Ext.data.Store({
					id : 'id',
					proxy : new Ext.data.HttpProxy({
						url : "/xf/areas",
						method : 'GET'
					}),
					reader : new Ext.data.JsonReader({
						root : 'rows',
						fields : ['id', 'name']
					})
				})
			},{
				fieldLabel : divo.required+"法定代表人",
				name : "corporation",
				maxLength : 20,
				width:300
			},{
				fieldLabel : divo.required+"法定代表人电话",
				name : "corporation_tele",
				maxLength :40,
				width:300
			},{
				fieldLabel : divo.required+"主要负责人",
				name : "leader",
				maxLength : 20,
				width:300
			},{
				fieldLabel : divo.required+"主要负责人电话",
				name : "leader_tele",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"主要负责人手机号",
				name : "leader_mobile",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"单位电话号码",
				name : "tele",
				maxLength : 40,
				width:180
			},{
				fieldLabel : divo.required+"单位传真号码",
				name : "fax",
				maxLength : 40,
				width:300
			},{
				fieldLabel : divo.required+"邮编",
				name : "post_code",
				maxLength : 10,
				width:300
			},{
				fieldLabel : divo.required+"工商注册地址",
				name : "register_address",
				width:300
			},{
				fieldLabel : divo.required+"实际经营地址",
				name : "address",
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"注册资金(万元)",
				name : "register_money",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"员工人数",
				name : "employee_count",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : 'numberfield',
				fieldLabel : divo.required+"技术员工人数",
				name : "tech_count",
				decimalPrecision : 0,
				allowNegative : false,
				width:300
			},{
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海消防协会消防产业委员会会员单位",
				items: [
                    {boxLabel: '是', name: 'is_member',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_member',inputValue: false}
                ]
			},{
				xtype : "radiogroup",
				width : 160,
				fieldLabel : "上海市消防产业诚信承诺单位",
				items: [
                    {boxLabel: '是', name: 'is_trustful',inputValue: true, checked: true},
                    {boxLabel: '否', name: 'is_trustful',inputValue: false}
                ]
			},{
				fieldLabel : "备注",
				name : "note",
				width:300
			}]
		})

		form.xf.ProjecterAddOrEditForm.superclass.initComponent.call(this);
	},
	//重写
    loadItem : function() {
		Ext.Ajax.request({
			scope : this,
			url : "/xf/projecters/"+this.projecterId,
			method : 'GET',
			success : function(response, options) {
				var resp = Ext.decode(response.responseText);
				this.getForm().setValues(resp.data)
			},
			failure : function(response, options) {
				this.alert(response.responseText);
			}
		})
    },
	// public
	save : function(callbackOnSuccess) {
		var item = this.getForm().getObjectValues()
		item.is_member = eval(item.is_member)
		item.is_trustful = eval(item.is_trustful)
		item.is_recommended = eval(item.is_recommended)

		Ext.Ajax.request({
			scope : this,
			url : "/xf/projecters"+(this.adding?"":"/"+this.projecterId),
			waitMsg : "正在提交...",
			method : (this.adding?'POST':'PUT'),
			jsonData : item,
			success : function(response, options) {
				var resp = Ext.decode(response.responseText)
				if (!resp.success) {
					this.getForm().markInvalid(resp.errors)
				} else {
					callbackOnSuccess(resp.id)
				}
			},
			failure : function(response, options) {
				this.alert(response.responseText)	
			}
		})
	}
})

Ext.reg("form.xf.ProjecterAddOrEditForm", form.xf.ProjecterAddOrEditForm)
// EOP

;/**
 * 工程施工单位新建或修改窗口
 *
 * --------------------------------------------------------------
 * 消息：
 * 工程施工单位新增或修改了
 * 
 * 消息名：     			
 * window.xf.ProjecterChanged    
 * 
 * 消息内容：
 * {int} sender 本组件的id值
 * --------------------------------------------------------------
 */
window.xf.ProjecterAddOrEditWindow = Ext.extend(Ext.Window, {
	cancelAction : "hide",  //还可以取值：destroy
	closeAction : "hide",
	adding : false,
	projecterId : null,
	initComponent : function() {
		Ext.apply(this,{
			title : (this.adding?'新建':'修改')+' 工程施工单位',
			width : 670,
			height : 550,
			modal : true,
			stateful : true,
			stateId : 'xf-projecter-win',
			closable : true,
			maximizable : false,
			minimizable : false,
			layout : "fit",
			buttons : [{
				text : "确定",
				handler : this.onSave,
				scope : this
			}, {
				text : "取消",
				handler : this.onCancel,
				scope : this
			}],
			items : {
				xtype : "form.xf.ProjecterAddOrEditForm",
				adding : this.adding,
				projecterId : this.projecterId
			}
		});
		
		window.xf.ProjecterAddOrEditWindow.superclass.initComponent.call(this);
	},
	onSave : function() {
		this.items.itemAt(0).save(this.onSaveSucccess.createDelegate(this))
	},
	onSaveSucccess : function(id) {
		this.say(this.adding ? '新建成功, 请继续新建。':'修改已经保存')
		if (!this.adding)
		   this.close()
		else   
		   this.items.itemAt(0).clearForm()
		
		this.publish("window.xf.ProjecterChanged",{
			sender:this.id,
			id : id
		})
	}
});
// EOP

;